Programming Atmel AVRs with the PICKit2 programmer

August 25th, 2010 Leave a comment Go to comments

Programming AVR microcontrollers with the PICKit2 programmer



  • with no PICKit2 hardware or firmware changes
  • use your favorite AVR programming software compatible with the AVRISP (serial) programmer

PK2AVRISP

Is an application that simulates the behavior of the AVRISP programmer. It decodes the AVRISP commands received from the virtual serial port, translates the commands into PICKit2 commands and send them to the PICKit2 programmer via USB.

PK2AVRISP acts as a bridge between the AVR programming application and the PICKit2 programmer, emulating the AVRISP protocol for the AVR programming app.

You will also need com0com to create 2 bridged virtual serial ports. (for example COM3 ad COM4). You can use any other software capable of doing this, but com0com is free/open source.

If AVRISP complains about some missing files (this happens on WinXP), you will also need to install “Microsoft Visual C++ 2008 Redistributable Package” from here: http://www.microsoft.com/downloads/details.aspx?familyid=9B2DA534-3E03-4391-8A4D-074B9F2BC1BF&displaylang=en

Download

PK2AVRISP - PK2AVRISP v0.3 only

changelog:

v0.3: fixed some delay issues when programming EEPROM

v 0.2:

-removed different polling methods on write eeprom/flash, using delay method even if the programmer software requests other method. SPI polling is time consuming with PICKit2 protocol and unstable.

-added 2 buttons “VDD ON” and “VDD OFF” to turn PICKit2 VDD ON and OFF if you need to power from PICKit2

-added 2 command line parameter support:

-log    *Saves to a txt file a log of the AVRISP protocol traffic

-p<SerialPort>    *select the serial port at start-up e.g. -pCOM4

com0com + Visual C++ redistributable

or

PK2AVRISP + com0com+ VC++ redistributable

How to connect the PICKit2 to the AVR microcontroller

PICKit2 to AVRISP pinout

Example connection for ATmega8

Note that PB2/SS pin must be pulled down to GROUND during programming, this can be achieved by connecting the pin to RESET or can be wired to GROUND.

VDD needs to be connected only if the target board is not powered. If the board has an external power supply, DO NOT connect VDD to PICKit2.

How to use

  • connect the PICKit2 to the AVR microcontroller (and PICKit2 to the PC)
  • make sure you have installed the 2 bridged virtual serial ports (for the example I’ll name them COM3 and COM4)
  • start PK2AVRISP (it should have detected your PICKit2 programmer) and select one of the 2 serial ports (for example COM3)
  • in your AVR programming application select the programmer AVRISP (or compatible like STK500)
  • for the selected programmer select the serial port the 2nd serial port from the created 2(in our example is COM4)
  • now you can use the programmer commands.

AVR programming applications

I have tested PK2AVRISP with the following applications:

  • CodeVision AVR (select AVRISP/STK500 programmer)
  • AVRStudio (AVRISP)
  • avrdude (Windows) (I had to select stk500v2 programmer)

The tests were made with ATmega8 microcontroller.

Update: I made some tests with ATtiny2313 and it works fine. It should work with all microcontrollers supported by AVRISP.

Update: Test were made with ATMega128. Some EEPROM programming issues were found and fixed in v0.3

The project is in alpha stage, only a few tests were made, so use it at your own risk. You should also read the PICKit2 license agreement.

You want to say “THANK YOU”? You can buy me a beer.

  1. JimmyJ
    November 20th, 2010 at 13:04 | #1

    AVRDUDE supports pickit2 with the appropriate patch. There is a pickit2 patch at http://savannah.nongnu.org/patch/?7184

  2. Wilmar
    November 22nd, 2010 at 02:13 | #2

    Hi!!, support ATMEGA16???? ty!

  3. ravinder
    November 29th, 2010 at 09:48 | #3

    I have Pickit2 ,but on my Laptop their is no Com port available it has one com3 for internal modem.My question is when trying to program the PKTAVRISP is showing could not open port .Is their any remedy for Using laptop with no com ports .

  4. admin
    November 29th, 2010 at 20:19 | #4

    @ravinder
    You don’t need any physical serial ports, you need to install 2 virtual ports with com0com and to use these ports with pk2avrisp.
    Please read the instructions.
    regards

  5. Ronald
    November 30th, 2010 at 17:43 | #5

    I am using the app, but it keeps telling me that cannot open port, tried connecting using hyperterminal and the ports are working. any solutions.

  6. admin
    December 1st, 2010 at 08:48 | #6

    Make sure only one instance of the program is running and make sure that another program (like hyperterm) is NOT using the com port. One serial port can be opened by a single program once.

  7. Jonathan
    December 24th, 2010 at 03:10 | #7

    Hi i’m from Argentina.

    First of all I would like to thank you. A recommendation to all users of this software.
    1 – Using Eltima software to create virtual COM ports.
    2 – Use AVR_burn _o_Mat as software programming in conjunction with AVRDUDE.
    3 – In Windows 7 to run the software as administrator.
    4 – In case of using WinAVR, when configuring the Makefile, use as a programmer stk500v2. In the port option to use the software created.

    For the following system fails:
    - AVRStudio
    - CodevisionAVR
    - 7 64 bit win AVRDUDE

    Following the above recommendations it has worked with the following devices:
    - ATmega8
    - ATmega48
    - ATmega644 – 20PU
    - ATtiny2313
    - ATmega328P with some minor problems.
    - ATmega32
    - ATmega168
    - ATmega 128 with some speed issues …. but program and reads well

  8. mogli
    December 30th, 2010 at 18:35 | #8

    Hello,

    WinXP Sp3,
    WinAVR,
    AVRSTUDIO4
    AVRTOOLCHAIN

    Atmega88

    Pickit2 is accepted as avrisp or stk500, but when trying to burn or read from or on chip:

    Programmer not found! Check your Connections!

    Setting mode and device parameters.. OK!
    Entering programming mode.. FAILED!
    Leaving programming mode.. FAILED!

    Best regards,

    mogli

  9. Andy
    January 24th, 2011 at 11:26 | #9

    Hi i’m from Ukraine

    WinXP Sp3

    The system does not work properly. PicKit2 starts but programming does not occur.

    avrdude.exe -C avrdude.conf -p m16 -P com3 -c stk500v2 -U eeprom:r:E:\tmp\eep.hex:i

    avrdude.exe: stk500v2_command(): command failed
    avrdude.exe: initialization failed, rc=-1
    Double check connections and try again, or use -F to override
    this check.

    avrdude.exe done. Thank you.

  10. July 24th, 2011 at 00:23 | #10

    Has anyone gotten this to work with the Chinese pickit2 clones (i.e., mini kit 2) that’re around $20 all over ebay? I have one and it’s close, but the data is always slightly distorted after it’s programmed. It always fails verification, and when I read the flash there are about 10 “F” characters in a row every 6 or 7 lines. I’ve tried many things but it doesn’t seem to help. The same problem occurs with AVR Studio and AVRDUDE., using the avrisp and stk programmer setting.

    Is this just my lot in life? … it’s not designed to work with bootleg pickit 2 programmers? Any input you have would be greatly appreciated!

  11. July 24th, 2011 at 00:33 | #11

    FIRST 6 LINES OF PROGRAM TO GET LOADED:
    :1000000019C020C01FC01EC01DC01CC01BC01AC00C
    :1000100019C018C017C016C015C014C013C012C034
    :1000200011C010C00FC00EC00DC00CC00BC00AC064
    :1000300009C008C011241FBECFEFD2E0DEBFCDBF84
    :1000400002D00FC0DDCF8FEF8AB94FEF28EA31E63B
    :100050004BB9C9010197F1F71BB8C9010197F1F735

    FIRST 6 LINES OF WHAT ACTUALLY IS LOADED:
    :1000000019C020C01FC0FFFFFFFFFFFFFFFF1AC086
    :1000100019C018C017C016C015C014C013C012C034
    :1000200011C010C00FC00EC00DC00CC00BC00AC064
    :10003000FFFFFFFFFFFFFFFFCFEFD2E0DEBFCDBF2F
    :1000400002D00FC0DDCF8FEF8AB94FEF28EA31E63B
    :100050004BB9C9010197F1F71BB8C9010197F1F735

    any ideas?

  12. Gert
    September 16th, 2011 at 19:34 | #12

    Hi,

    I have tried using the software, but no success, I get the following error message using AVR studio 5 (after adding the STK500):

    “Code:1 ,Service: ,Message from peer: The signature of the attached tool is AVRISP_2, which is unexpected.” If the PKAVRISP is not running, then the connection times out.

    I’ve tried using AVR studio 4, but if I try to connect, AVR studio stops responding and I have to kill the process.

    Question: does the pickit2 require a specific OS firmware version in order to work with PICKit2 AVRISP? Any other ideas that I could try?

  13. Gert
    September 17th, 2011 at 19:00 | #13

    @Gert
    I’ve read previous posts on forum and concluded that I should try AVRdude (included with WinAVR), which worked. I was able to read device, but haven’t tried writing (so not sure if timing is working 100%), but will post result later. I’m new to AVR programming, so for other first timers, I recommend AVR burn-O mat, which is a GUI front end for AVRdude.

    To those struggling with a “Can not open port error”, if noticed that PICKit2AVRISP does not like a Com port name other than “ComX”, where X is an integer. If I changed the Port name in the settings of com0com, to e.g. Com3, PICKit2AVRISP was able to open the port.

Comment pages
  1. No trackbacks yet.