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 » AVR programming a SPI slave.

February 07, 2014
by sask55
sask55's Avatar

I have the SPI master, three SPI slaves and a AVR ISP Programmer connected on a SPI buss (ie the MISO,MOSI and SCK pins on each are connected in parallel). I am experiencing problems setting up communications between the micros and the programmer. I am using a simple rotary selector switch on the reset pins of each chip, to allow me to select which chip that the ISP programmer is intended to communicate with. The idea of selecting which chip to program by directing the programmers chip reset signal to the appropriate chip reset pin works well.

This is all working as I hoped except for one major problem. The issue is that any chip that is initialized (in coded) as a SPI slave appears to hamper the communications of all the other chips with the ISP programmer. The connections to the pins on the SPI master do not seam to cause any problems they can remain connected to the buss all of the time.

I have discovered that in order to set up communication and carry out a programming, I have to disconnect the MISO pin on all of the SPI slave chips, from the buss, to allow communication between the programmer and another chip on the buss. In other words there can only be one of the slave chip MISO pins connected to the buss at any time which will allow communication with the programmer for that micro only.

For me the major appeal and value of the SPI programmer concept is the ability to program any of the chips in place on the board. Can I modify the setup in some way (hardware or software) to allow all of the SPI connections to the chips to remain on the SPI buss all of the time?

I have considered placing a switch on each of the MISO pin connection the slave chips. This would allow me to isolate the slave that I was intending to program. This approach will work but does not seam straightforward or eloquent. I was hoping for something where I would not have to fiddle around with a rotary selector switch as well as three other switches each time I want to change the code on a chip chip and then have to reset everything to allow SPI communication between the master and slaves.

Any suggestions or ideas would be appreciated.

Darryl

February 07, 2014
by Noter
Noter's Avatar

Maybe try to isolate the active miso pins from the programmer and the target chips with low value resistors. Arrange wires physically to have a star topology for the miso line with the programmer in the center instead of of daisy chained. Then I would try a 220 ohm resistor between the programmer and each miso pin. I haven't done it with SPI but I have used small resistors for other isolation needs in the past. It should work as long as there is not much current in normal operation so the voltage drop is negligible. I suggest 220 ohm because it will flow only 23ma between 0v and 5v and practically nothing between a pin configured output and others as input which is the normal mode.

February 07, 2014
by sask55
sask55's Avatar

Thanks Noter

I think I may have it working now.

After I read your post I thought of an idea. I was wandering if I could control the issue by contolling the slave select pins on the slave chips while the programmer is in use. I did a couple of experiments. It appears that a 10K resistor on the SS pins of the slaves to +5V will allow the programmer to address any of the chips. All I have to do is I select the corresponding reset pin with the rotary switch. The master chip’s slave selection pins should easily sink enough current to pull the SS low when communicating with a slave. I dont have a working code on my master chip right now. I am in the process of rewriting my master chip code so I did not test the SPI master/slave communications yet. I don’t see why it will not work. It seams kind of simple now.

March 15, 2014
by sask55
sask55's Avatar

I have decided to post a few details on the steps that found necessary to allow me to do ISP programming on a SPI bus. I realize that none of this is new and may possibly be redundant or obvious o some. My experiences may help avoid some frustration or save some time if anyone is intending to set up ISP programming on a SPI bus.

My original intention was to do ISP programming using a fifth micro on the SPI bus. I was hoping to control the reset pin levels on the master and the slaves using software controlled pins on the ISP programmer chip. I was unsuccessful accomplishing readable ISP programming using that idea. I then decide to use manual switches to select which chip to program and make use of an inexpensive ISP programmer that can remain connected to the SPI bus for as long as necessary.

This setup has been working very well for me for a couple of months now and is a vast improvement over what I had been doing before, that is removing each chip and programming using the boot loader. I can now program any of the three slaves or the mater in place on their boards in a mater of seconds.

There are a couple of small hardware adaptations that I found necessary to allow the ISP programming to work In my setup I have four separate PC boards connected using plug in type connectors. Each of the slave chips as well as the master chip is mounted on it own individual PC board. There are four plug in type connectors mounted on master board that are used to establish connections to the slave boards as well as the ISP programmer.

1 I found it necessary to place a resistor between the +5volt power and the slave selection pins on the master chip. I think that by hold the SS pins high on each of the slave chips the level is not floating which allows the ISP programmer to pull the appropriate SS pin low to establish communication and allow programming. Without these resistors in place it I was not able to accomplish reliable ISP programming on the save chips.

2 I also found it necessary to disconnect the SCK pin on the master chip from the SPI bus in order to reliably program the slave chips. It seams that the master chip was occasionally interfering with the ISP programmer control of the SCK bus line during programming of a slave chip, by temporally removing the master SCK pin from the bus during programming I have eliminated any issues I was experiencing.

My current setup has been working very well. Two- way SPI communications between the master and the slaves performs reliably as long as he switch on the master SCK is closed. The rotary selector switch can be at any location for Master /Slave SPI. To reprogram the slave chip using the ISP programmer I ensure that the master is selected on the rotary switch, then click the AutoProgram button on the khazama AVR Programmer. To reprogram a slave the sector switch is set to “point” at the desired chip, I open the Master SCK isolation switch and then click the AutoProgram button on the khazama AVR Programmer.

wireing diagram

I am disheartened to see this site and forum slowly becoming less active. I often find that searching this Nerdkit forum or posting a question is the best resources I can find for my electronic interests. As others have sad before I hate the thought that it could be nearing an end. So I thought I would post something that may be of some interest of someone. I feel like I know at least a few of the regular contributors and hope I don’t loss this connection.

March 16, 2014
by JKITSON
JKITSON's Avatar

Darryl

Thanks for post. I have started to print posts like yours and placing in a binder book. This way if the site dies I have some of the info.. Your description and schematic was clear and very usefull....Thanks again

Jim

March 17, 2014
by Ralphxyz
Ralphxyz's Avatar

Stay in touch rhulslander gmail

Post a Reply

Please log in to post a reply.

Did you know that you can build a digital read out (DRO) for a lathe or milling machine? Learn more...