PICkit 2 as an AVR programmer: Difference between revisions

From richmondmakerlabs.uk
Jump to navigation Jump to search
IanM (talk | contribs)
IanM (talk | contribs)
No edit summary
 
Line 52: Line 52:


which indicates successful connection to the PICkit 2, but of course no connection to an AVR MCU target.
which indicates successful connection to the PICkit 2, but of course no connection to an AVR MCU target.
Once the PICkit 2 is successfully under the control of AVRdude, its safe to connect your target.  If the target has any power source apart from the PICkit 2, always disconnect the target before disconnecting the PICkit 2 or turning off or suspending the PC.


==Connections to an AVR MCU==
==Connections to an AVR MCU==
Line 78: Line 77:


Also see https://learn.sparkfun.com/tutorials/installing-an-arduino-bootloader/all
Also see https://learn.sparkfun.com/tutorials/installing-an-arduino-bootloader/all
Once the PICkit 2 is successfully under the control of AVRdude, its safe to connect your target.  If the target has any power source apart from the PICkit 2, always disconnect the target before disconnecting the PICkit 2 or turning off or suspending the PC.  Even if the target is independently powered, the PICkit 2 requires the Vcc Targ. connection to set its I/O levels.

Latest revision as of 14:55, 18 October 2024

We have a Microchip PICkit 2 on the electronics bench. It lives in the cardboard tray at the woodstore end of the shelves, with the logic analyser. There should be two 12 cm programming cables with it - grey ribbon cable with black ends - 6 pin SIL M-F for Microchip PIC ICSP, and 6 pin SIL M to 3x2 F for Atmel AVR ISP, and also an 18 cm 6 pin SIL M to individual colour coded pins breadboard programming cable.

These are User:IanM's installation notes.

AVRDUDE support

Recent versions of AVRDUDE support Microchip PICkit 2 as an AVR ISP programmer. Use command line option: -p pickit2

Installation (Windows)

I assume you already have AVRDUDE, and possibly a GUI for it installed.

Run Zadig (from https://zadig.akeo.ie/ ) and do 'Options=>'List all devices'. Select the PICkit 2 and install the WinUSB (libusb) driver. If problems occur later return to this step and try the libusbK driver.

Alternatively (my preference) use libusb-win32 and install a filter driver for the PICkit 2 so both AVRDUDE and the PICkit software can use it. N.B. libusb-win32 v1.4 filter installer is broken on Win10+. Use Zadig to get libusb-win32 installed with the files in the right place, then device manager to revert to the OEM or Microsoft driver (without deleting any files), then reinstall the driver as a filter using libusb-win32 v1.4 filter installer.

If unsure which device is the PICkit 2, its VID: 04D8 PID: 0033.

Reverting to programming PICs

N.B. If not using a filter driver, to revert the PICkit 2 to the original USB HID driver for use with MPLAB or the PICkit 2 GUI or command line PIC programming utility you need to 'De-Zadig' the PICkit 2 by uninstalling it from Device Manager, selecting the option to delete all drivers, then scan for hardware changes to let windows reinstall it. If successful, it should appear as 'HID-compliant vendor-defined device' under 'Human Interface Devices'. If that fails, use Zadig to force it to be a 'USB Serial (CDC)' device (which will not work) then uninstall that from under 'Ports (COM & LPT)' in Device Manager as above.

If you are using a libusb-win32 filter driver, both MPLAB and the PICkit 2 GUI should still work with it installed. If they don't uninstall as above.

Arduino IDE Support

To add PICkit 2 as a programmer in the Arduino v1.8x IDE, append the following lines to "programmers.txt" after making a backup copy:

# User added PICkit 2
pickit2.name=PICkit 2
pickit2.communication=usb
pickit2.protocol=pickit2
pickit2.program.protocol=pickit2
pickit2.program.tool=avrdude
pickit2.program.extra_params=-v -V

If Arduino IDE 1.8x is installed for all users, that can be found at

  "C:\Program Files (x86)\Arduino\hardware\arduino\avr\programmers.txt"

but if its only installed for the current user, or if you have upgraded or downgraded the AVR core, it may be at

  "C:\Users\<your_user_name>\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.6\programmers.txt"

which is easiest to find by doing File => Preferences in the IDE, clicking the link for preferences.txt at the bottom of the Preferences dialog and in the resulting explorer window, drilling down through packages etc. till you reach programmers.txt.

You *MUST* restart the IDE to see the added PICkit 2 programmer in the Tools => Programmer: ... menu.

Test the installation by selecting PICkit 2 as the programmer in the Arduino IDE and, with an AVR based board selected but no target connected, do 'Burn bootloader'. You should get a long and detailed report ending:

avrdude: MicroChip's PICkit2 Programmer firmware version 2.32.0
avrdude: initialization failed, rc=-2
         Double check connections and try again, or use -F to override
         this check.

Error while burning bootloader.

which indicates successful connection to the PICkit 2, but of course no connection to an AVR MCU target.

Connections to an AVR MCU

The PICkit 2 pin 1 is identified by a white arrow on the upper case.

Pin assignments are:

PK2| AVR       |2x3 ISP|2x5 ISP|Breadboard| ATmega328P
pin| Signal    |header |header |ICSP cable| DIP pin
===|===========|=======|=======|==========|==========
 1 - RST       - 5     - 5     - Yellow   - 1 + 10K pullup    
 2 - Vcc Targ. - 2     - 2     - Red      - 7,20 } + 100nF
 3 - Gnd       - 6     - 10    - Black    - 8,22 } decoupling
 4 - MISO      - 1     - 9     - Blue     - 18 (PB4/D12)
 5 - SCLK      - 3     - 7     - White    - 19 (PB5/D13)
 6 - MOSI      - 4     - 1     - Green    - 17 (PB3/D11)
 ┌─┐
>│1│                    ┌───┐
 │2│            ┌───┐   │1 2│
 │3│            │1 2│   │3 4│
 │4│             3 4│    5 6│
 │5│            │5 6│   │7 8│
 │6│            └───┘   │9 o│10
 └─┘                    └───┘   

Also see https://learn.sparkfun.com/tutorials/installing-an-arduino-bootloader/all

Once the PICkit 2 is successfully under the control of AVRdude, its safe to connect your target. If the target has any power source apart from the PICkit 2, always disconnect the target before disconnecting the PICkit 2 or turning off or suspending the PC. Even if the target is independently powered, the PICkit 2 requires the Vcc Targ. connection to set its I/O levels.