### Short version (for those who just need the solution)

If you get the error message that your PICkit3's firmware is out-of-date, go get MPLAB 8 (only for Windows) and let it upgrade the firmware automatically (click Programmer -> Select Programmer -> PICkit3). Then go back to MPLAB X and program your device (of course, select correct target chip). I cannot believe this solution either. But it is from Microchip's support team.

### Full story

I will be team-teaching Embedded System class next semester, with another faculty member who offered this class previously, using Microchip's PIC24 architecture. However, my first contact with PIC24 is very frustrating.

Microchip released a new IDE, MPLAB X, for developing and downloading programs for their chips. Unlike previous one, it supports Linux (whereas ATMEL and Texas Instruments have done years ago). I ordered PICkit3 (the downloader or hardware programmer) and Explorer 16 (the dev kit) from Microchip in the hope to use their technical support later.

### Out-of-date firmware in PICkit3

However, downloading programs using PICkit3 and MPLAB X frustrated me a lot. The error message didn't help or the information was not consistent with what happened.

Connecting to MPLAB PICkit 3...
Firmware Suite Version.....01.22.08
Firmware type..............dsPIC33F/24F/24H

Your PICkit 3 firmware version is too old. You must have firmware version 01.22.08 or higher to use MPLAB X. Connection Failed.


What?

I tried again and it seems that MPLAB X helped me update the firmware:
Connecting to MPLAB PICkit 3...
Firmware Suite Version.....01.22.08
Firmware type..............dsPIC33F/24F/24H

Connection Failed.

So I tried again and but even the firmware was messed up:
Connecting to MPLAB PICkit 3...
Firmware Suite Version.....01.22.08
Firmware type..............Unknown Firmware Type

Connection Failed.

Since the firmware was never updated, I contacted Microchip's technical support.

#### Troubleshooting

After a week, they replied and gave me a very weird solution: updating the firmware using an older version (8) of MPLAB on Windows. I tried and I even got error messages on Windows.

Just when I was about to send the Pickit3 back, I plugged it back to my Linux box for last try and some miracle happened. (I guess what happened was that MPLAB 8 on Windows upgraded the firmware to a version from which MPLAB X kept upgrading.)
Connecting to MPLAB PICkit 3...
Firmware Suite Version.....01.28.90
Firmware type..............PIC18F

Firmware Suite Version.....01.28.92
Firmware type..............dsPIC33F/24F/24H

Target detected
Device ID Revision = 3044

The following memory area(s) will be programmed:

Programming...
Programming/Verify complete 

### Conclusion

It took me 2 weeks just to run a hello-world program. I have to say that Microchip does not pave a way for fresh people to learn their stuff. Just a few example:
• Why did they send me hardware with firmware greatly out-of-date anyway? And this cannot be solved in their latest software. Instead, I need a previous version to do that. This is a broken solution.
• The user guide for Explorer16 freezes at its 2005 version whereas the hardware programmer and IDE have changed a lot since then. For example, I didn't know how to connect the Explorer16 with PICkit3. There are two ways and one might burn your circuit.
• The "official" PIC24 textbook, written by a Microchip engineering, has wrong example programs. Like the very early one below:
int main(void) {
PORTA=0xff;
TRISA = 0;
return 0;
}
How can you output data to Port A before it is set as an output? The first two lines need to be swapped. You won't get the correct value even in software-emulated debugger.
• The unreliability issue of the hardware programmer PICkit3. I will mention it in another post.

Hence, my first contact with Microchip's solution was not pleasant.

Anonymous said...

On the later PICs, setting the LAT values before the TRIS is a good idea, since it pre-loads the value that will be output before the pins are changed from high impedance input to a driven output.

This can be useful to avoid glitches if you:
- Set the pin to output.
- The default value in the LATx register is applied to the pins.
- You set the LATx pin state to what you really want.

Andras Fekete said...

The example code isn't wrong. You can actually have PORTA line before the TRISA line, it's just that the output will not be configured as one until the TRISA line is executed. Having it in the other order is correct too, it's just that you may get a glitch if you don't set up the output value before turning off the tristate.

Laz David said...

I agree with you, using Explorer 16 and Pickit 3 for a couple of years. There are many mistakes in any (too many) documentation, nothing is really well explained, we always have to experiment in order to succeed, say blinking a simple led. This is a shame. I trully consider moving to other MCU brand now, althouh I spent some money in start kits, explorer, pims, pictail cards, and so on. tired about Microchip, really !

Anonymous said...

Documentation errors seem to increase - all over the industry. Documentation seems to be a unwanted task. Most major companies offer only online docs for their products if they offer a detailed doc at all. Microchip docs are not perfect but far better than others.