NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » ISP programming questions.

September 26, 2013
by sask55
sask55's Avatar

To date the only programming I have done using ISP is loading bootloader on fresh MCSs. Part of my reluctance to use ISP programming for anything but loading a bootloader is a result of my lack of understanding of how to incorporate it in my projects.

Like many projects, most of my projects have a considerable amount of specific circuitry built around the MCU. In many cases the project is making use of serial UART communication and therefore a USB adapter is permanently incorporated in the design. The MISO, MOSI, SCK, SS pins are often wired for SPI between master and slave chips, if not for some other functions on the board. I don’t understand how to make them available for ISP communication if they are required for and wired to some other purpose in the project.

In my project I may be doing things the hard way but reprogramming the master chip will involve flipping a switch occasionally, but actually for me that is a small inconvenience when compared to reprogramming any of the slave chips. To modify the programme on a slave chip I currently have to physically remove the chip from the project board place it in a second board that I have setup to use for program changes. After I have uploaded the software modifications I then remove the chip from the programming board and replace it into the project board in order to do any sort of test on my changes. Flipping a switch is the least of my problems. Reprogramming on the slave chips is tedious and error prone, all that removing/reinstalling of the chips results in bad connections and bent pins.

In my current design I have a total of only 2 unassigned (unused) pins on the master chip for my project. There are no unassigned pins on any of the three slave chips in this project. I could possibly forgo some of the functionality on the motor controller chips and therefore free up a pin or two on each slave if the potential reprogramming benefit was substantial.

I am wandering if it may be possible to use ISP programming to program the slave chips, in place, from the master chip without ever requiring me to move any chips? The scenario I am wandering about would involve setting up the master chip with a slightly modified version of Noter’s ISP programmer code as well as all the code currently used on my project. An additional switch could be placed on the board. A conditional statement in the mater chip code would direct the master functionality to either run the project code or the ISP code depending on the position of that switch. My hope would be to produce a system to reprogram the slave chips using ISP through the uart that is already connected to the master. Ideally I could set up some type of software selection process where I would toggle through the three slave chips with a button push. After selecting the appropriate slave the master would function as an ISP programmer as long as the master mode switch was set to do so. After reprogramming a salve using ISP the master mode switch could be reset to run my project software. In this scenario reprogramming on the master chip would still involve the bootloader on that chip and serial uart from a PC and the switch to do that would still be used. This would be an enormous improvement to what I am now doing, and would greatly simplify any reprogramming that I may consider on the slave chips even after the project is completed.

My questions are. Dose that sound like it would be at all possible? Can I actually use the same connections between the master and slave chips to do either ISP or SPI depending on the software on the master? How many additional pins may be required on ether the Master or the slave chips to accomplish the ISP programmer target chip selection using software? I do not have the time now to look more closely into this idea. Does anyone think it is worth investigating this idea or am I completely missing the entire ISP concept?

September 26, 2013
by Noter
Noter's Avatar

I'm not sure I have the whole picture but surely you can improve your setup to ease programming. At one point I had an i2c master and a some slaves and I programmed them all with a single ISP programmer. That was quite a while back and I don't think I saved any of the code but basically what I did was modify the nerdkit ISP programmer to use some more pins for selecting the target chip and added an extra command in the protocol. In my makefile I sent that command to the programmer to select the target before invoking avrdude. But I was not using the SPI port on any of the target chips for anything but programming. It's more complicated since you are using SPI to communicate between your devices. Seems like it should work but the issue that comes to mind is the master doesn't use SS to enable SPI communications so it would recieve all the data that was on the buss when programming a slave. The other slaves would ignore the data depending on the state of their SS pin. Perhaps using one of the unassigned pins to tell the master to ignore the SPI buss and deselect all slaves when programming a slave would work.

I guess I think it would be a better approach to work it out in the ISP programmer rather than merging that functionality with your master. I assume you already have a pin for each slave SS and another for each slave RESET would be needed to program and it sounds like you don't have enough extra pins on your master.

Makes for an interesting project. More thought required to work out the details but I think it can definitely be done. You could have your master code open in one editor window, slave code in another, and one makefile that compiles one/both as needed and programs the appropriate chip(s) all automatically. If your programing style is like mine, literally hundreds of compiles during the course of a project, you will save a ton of time.

September 27, 2013
by sask55
sask55's Avatar

Thanks Noter

I feel that I am way out of my league, and busy this time of year, but I was thinking of perhaps freeing up more pins on the master if I cant think of anything better.

OR! Maybe something along these lines, I install a multi connection plug on the project board. Since all four of the micros on the project board now are sharing connections to the SPI bus I use that bus to send ISP programming the chips. I could install pull up resistors on all four of the project micros RESET pins and also connect the RESET pins to that ISP programming plug connection. By plugging in my fifth micro that has a version of your ISP programmer on I would effectively have data connection to the MISO,MOSI pins on any of the four project MCUs. I would also have a connection to control the RESET pins on any of the four project MCUs from the newly connected programming MCU.

Would something along these lines allow me to program any one of the four project micros with ISP by holding the RESET pins low on the other chips when they are not being programmed? I think a question is would the other MCUs interfere with the ISP communication if there resets are held low but there MSIO and MOSI pins remain connected to the bus.

September 27, 2013
by Noter
Noter's Avatar

I think you're on the right track. Keep in mind that pulling reset low is what enables ISP programming for a chip so only the chip you are programming could have it's reset pulled low. The others all have to continue running and ignore data on the SPI buss for the duration of the programming cycle. Fairly easy for slaves since they are enabled when SS is pulled low but the master will need further consideration.

Maybe just start by ISP programming only your master and get comfortable with that before expanding to the slaves. Definitely need a connector or pins or some wires carefully soldered on your PCB to connect the programmer to the SPI buss. Also need a connection to the RESET pin on the master as well as GND. I'm unsure what the slave will do when it's SS pin is left floating by the master. Might need pull-ups enabled on the slave SS pin or if that doesn't work external pull-ups.

September 27, 2013
by sask55
sask55's Avatar

Thanks again Noter! this could be possibly the best advancement in terms of time saving I have seen in a long time .

When I get a chance, after harvest is completed, I will be setup to give this a try. I may require some advice to handle the ISP communication coding required. It seams to me that the output/input data pins on the ISP programmer chip will have to be swapped in the code when programming the master as compared to the slaves. For example pin 18 on the master (master out) shares the same bus connection as pin 17 on all the slaves (slave in).

A the very least the ISP programmer will be required to pull the appropriate chip RESET pin low and adjust its pin out configuration to match that of the chip it is programming (slave vs master). I am still not that clear on what make file changes may be required to change from programming one chip to the next.

This would save a huge amount of time and eliminate countless mistakes. I could have my project communication code open on one PC using the USB adapter and have the programming editor windows on a second machine. Completely removing all programming from the master chip uart would eliminate another annoying circumstance I was dealing with, where I continually had to close the project software com port connection in order to have the USB com port available to the programming software and vice versa. I know it may sound ridiculous to you that are familiar with ISP programmers but I have done that flip dozens, maybe hundreds, of time while setting up the master and the three slaves. Just testing a small change or error trapping routine was quite an ordeal.

September 27, 2013
by sask55
sask55's Avatar

Sorry after rethinking the pin out I see that I was wrong master pin 18 is not connected to slave pin 17 so there is no requirement to swap anything.

Post a Reply

Please log in to post a reply.

Did you know that you can follow NerdKits on Facebook, YouTube, and Twitter? Learn more...