NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Support Forum » How to keep slave working if SS is pulled high?
October 23, 2010 by kle8309 |
Ok, so I have a SPI setup for a master and a slave. I having trouble keeping the slave mcu working (like counting) while the master pull the ss line high. I just need help with the code. Here is my code for the slave:
|
---|---|
October 25, 2010 by hevans (NerdKits Staff) |
Hi kle8309, I'm not sure what you mean when you say the chip doesn't keep counting when the SS pin is pulled high. I can't think of a good reason why your chip would just stop working. I can see some possible timing issues in your code, and I can't quite follow what you are trying to do in some places. I would move the call to Salve_Init() to the beginning of the main loop outside the while(1) loop. It's possible your slave is just inside the init method whenever you are trying do send data from the master. Perhaps the best thing for you to try is to strip down your code and start smaller. Try to get one byte across from the master to the slave and display it, and then architect your code around that functionality. Let us know how your project comes along. Humberto |
October 25, 2010 by kle8309 |
So I have traced the run time execution to line 41 above, where the slave gets stuck in the while loop (waiting for master transmission to be completed aka SPIF==1). The one thing I noticed is that while the SS is pulled high, I can't change the SPIF to one. Any code inside the while loop from line 41 will work. The only way that the slave can turn off spi is when SS is low (when the master gives permission to the slave then it can go off on its own?) ps. What i meant by counting is like just incrementing a number like n++ |
October 26, 2010 by mrobbins (NerdKits Staff) |
Hi Kelvin, I don't think you actually need to have your code explicitly turning SPI on and off following SS -- just have it setup as a SPI slave, and stay as an SPI slave. Also, you shouldn't turn on PC5 as an output, because as a slave, the clocking is still done by the master. (This is ignored by the microcontroller anyway -- see table 18-1 on page 164 of the ATmega168 datasheet.) I think you could achieve what you intend by checking for SPIF from your main loop as an indication that a new character has been received, or using the SPI interrupt instead. Does that make sense for what you're trying to do? Mike |
Please log in to post a reply.
Did you know that you can see each keypress on a computer keyboard on an oscilloscope? Learn more...
|