Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have 6 dsPIC33F (16bit) controllers in the system and the system is quite big and complicated. All controllers are located on different PCBs and connected to each other through RS485 bus.

  1. First Pic controller (Master) is connected to PC and the rest of the controllers (5 slaves) are connected to Master using RS485 bus.
  2. To program master dsPIC uses MPLAB-ICD programmer connected to PC.
  3. Now To program Slave1 dsPIC we have to open the machine then locate the PCB and connect the programmer manually then program it.
  4. Similarly we follow the same procedure one by one for all controller by removing the programmer and connecting to respective PCB to program the dsPIC.

I want to program all the controllers through software one by one from PC without removing the MPLAB_ICD when it is connected between the Master and PC by default. Or is there any other method through hardware or software to program all controllers one by one from PC itself without doing it manually?

What hardware/software changes do I have to make to program the dsPIC without opening the system?

share|improve this question
I suggest your situation (though I don't know your numbers) might be resolved by ordering the controllers pre-programmed. Major retailers like Digikey can provide this as a reasonable value-added service, and if quant's are big enough, you can have this done directly at Microchip. – Scott Seidman Jun 24 '14 at 15:11
up vote 6 down vote accepted

I do pretty much this same thing with PIC32 devices with the exception that this is performed with a bootloader and not an ICD. We program the bootloader into each device when it is manufactured and tested using an MPLAB-ICD3. We then use the bootloader for firmware upgrades.

The bootloader is a modified version of the one provided by Microchip. The modifications were to allow pass-through communications with the slave devices. The PC loader application also needed to be modified. Here is how it works:

  1. Each device has two communications ports. One RS-232 port and one RS-485 port. The RS-232 port is usually only used by a master and all slaves may be programmed and configured via pass-through from that port. The slave devices may optionally be configured or programmed through their own RS-232 port.

  2. Each device has an 8-position dip-switch which sets the device address. Each device also has a master/slave select dip-switch to define the master. You could use a pre-defined address to designate the master, but we had reasons to need the separate switch which are not related to this question.

  3. Included in the communications protocols for all ports is a "Reset" command. This is used to reset the processor putting it into bootloader mode. The processor is in bootloader mode for a minimum of 0.5 seconds. This time is extended if bootloader packets are received (whether for it's device or for others). The PC loader application begins the bootload process by sending a global reset command to the master which will pass it on to the slaves.

  4. Each command and data from the PC comes in the form of a packet. An address byte is added to the beginning of each packet to designate the target device. The address is set by a control on the window of the PC loader program.

  5. All packets are acknowledged by the device that is addressed by the packet.

  6. A master will use a packet if it matches it's own address and acknowledge that packet. The master will pass-through the packet to the RS-485 port if the address does not match it's own. The master will pass-through acknowledge messages from the RS-485 port to the PC.

  7. A slave receiving a packet from the RS-485 port will use that packet and acknowledge it via the RS-485 port. If the packet is received from the RS-232 port (and the address matches), it will use and acknowledge the packet via that port.

  8. Due to the additional time required for pass-through communications, timeouts in the PC loader application had to be extended. For additional reasons related to our product, we are not supporting the use of Ethernet-based virtual COM ports for firmware upgrades. If this were done, additional time would be needed. Most USB to serial adapters (using virtual COM port drivers) work fine with this method.

share|improve this answer
what is device having 8-position dip-switch which sets the device address? from where i should get the bootloader for dsPIC33F, whether i have to modifiy the bootloader in order the program all the ic or is it readily available. After programming the bootloader Ic will be programmed through UART rx and tx pin? How to provide different address for different controller on PC loader program or such softwares on PC side is readily available. In short i want to know what all things i have to modify on PC software and bootloader or is it readily available. – user2722469 Jun 24 '14 at 11:57
@user2722469, a bootloader is a program that is set aside in a special location in the flash memory of your controller. Essentially, on RESET the bootloader is the first program to be executed. Either after bootloader execution, or if not bootloader is present, a simple JMP (jump) instruction is set such that the next instruction becomes the first instruction of your main program. There are likely many example bootloaders on the net for your particular controller, you just have to search for one and alter it for your purposes. – sherrellbc Jun 24 '14 at 12:45
This is a custom application which you will need to write yourself as I did (sorry, but I am not free to share source code). Since you already have slave devices on an RS-485 port, you most likely already have some means of communicating with the slaves using an address. Use that. There are two programs that you will need to write or modify. The bootloader that goes into the dsPIC and the loader program for the PC. You can probably get source code for a sample bootloader and loader program for your device from Microchip. I would start with this and modify it as needed. – Tut Jun 24 '14 at 12:46
... Also, yes, once a bootloader is in place you may program the device over UART - this is precisely what the Arduino platform does. Once their bootloader program is burned to the chip it can be programmed over USB. As for your different address question, this is done in either hardware or software. You can set compile-time constants for your addresses if you like, but it would then require a re-flash to be changed. Or you could do as Tut did and use an 8-bit dip-switch that could be read by the device when powered on. In this way, you observe the address and the chip knows its address – sherrellbc Jun 24 '14 at 12:48
Have a look at Microchip AN1094 Bootloader for dsPIC30F/33F and PIC24F/24H Devices. The source code for this is also posted on the Microchip website. I have not used it, but it looks like a good starting point for your bootloader and PC loader application (they call it the Host PC bootloader application). – Tut Jun 24 '14 at 13:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.