This tells the slave to get on and start processing the data.Įxample of connecting master to slave using SPI The incoming SPI data is collected in a buffer, and a flag set when a "significant byte" (in this case a newline) arrives. The slave is entirely interrupt-driven, thus it can doing other stuff. main loop - wait for flag set in interrupt routine } // end of interrupt routine SPI_STC_vect example: newline means time to process buffer have to send on master in, *slave out*īyte c = SPDR // grab byte from SPI Data Register Since the value on pin 10 is ignored, providing it is set as an output, then it can also be used as the SS line for your first, or only, slave. If configured as an output the Arduino ignores the value on that line, and thus the SPI hardware will not be put into slave mode. Pin 10 of the Arduino is the SS line - so does this mean you have to use it for the peripheral SS line? Or should it be kept high? The answer (from the Atmega documentation) is that the SS line (pin 10) must be configured as an output (regardless of what value is on it). Then, and only then, should they configure their MISO line (master in, slave out) to be an output, so they can send data back to the master. Thus, slaves should let each of the lines float (as inputs) unless their slave select is taken low. This way you only need 3 wires (plus ground) in total, plus one slave select for each slave. The way this is done is to tie the SCK, MISO and MISO lines together (for each slave) and have a separate SS (slave select) line for each slave. This is because the SPI hardware can be used to communicate with a number of slaves at once. There is a bit of confusion about the Slave Select pin. The code to produce this (in Arduino's C++ language) was: Also the slave should ignore any clock pulses now (they may be for a different peripheral). At this stage the slave should release the MISO line (configure it as an input, or "high impedance"). G - SS taken high to indicate end of the sequence of data.F - "No data" after "Fab" - however the SS is still enabled.Also the slave can place data on the MISO line for the master to simultaneously read in. This tells the slave to read the data on the MOSI line. For each of the 8 bits the SCK (clock) line is briefly brought high, and then low again. C - First character arrives (the letter "F" or 0x46 or 0b01000110).The slave can now prepare to notice clock pulses on the SCK line. At this point the slave should prepare to transfer data by setting the MOSI (master out, slave in) line, and the SCK (serial clock) as inputs, and the MISO (master in, slave out) as an output. B - SS taken low to enable the slave (peripheral).I put a trigger on the SS (Slave Select) pin so that the logic analyser would start analysing from when the sequence started.įrom the above graphic note the following points of interest: It shows the 3-character sequence "Fab" being sent from the Arduino. Let's start with an image - this is a screenshot taken with a logic analyser.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |