Go Down

Topic: SPI (Read 1 time) previous topic - next topic

michel1312

Hello.

Well, I continue to play with my 2 little arduino and make them communicate trhough SPI. But I got a question how can do soemthing like serial.availabal but in SPI ? or is there a buffer ? And if I resend from the master does it scratch the data if the slave didn't read ?

Thansk in adavce.

Ah soemthign else... on night in the documentation, I readed (or thought I readed) that if I use the atmega of an normal decimilia board but without ocillator, it act as a lillypad one. I dreamed or it's true can be fun to reduce coposant of my design if just 'naked' atmel and power supply.

Thanks.good day for all

Michel

biojae

Quote
Ah soemthign else... on night in the documentation, I readed (or thought I readed) that if I use the atmega of an normal decimilia board but without ocillator, it act as a lillypad one. I dreamed or it's true can be fun to reduce coposant of my design if just 'naked' atmel and power supply.


For that you need to set The Atmega's fuses to the internal oscillator, You need to make or buy a icsp programmer for it.
it is possible

wayoda

Hi,
Quote
Hello.

Well, I continue to play with my 2 little arduino and make them communicate trhough SPI. But I got a question how can do soemthing like serial.availabal but in SPI ? or is there a buffer ? And if I resend from the master does it scratch the data if the slave didn't read ?
Michel

I suggest you use the I2C-bus available on the Arduino for communication. The Wire-Library that comes with the Arduino-IDE allows you to turn your Arduino into either a Master- or Slave-I2C device.
In theory the same could be done with SPI, but I  haven't seen a library-implementation of a SPI-slavedevice yet.

I would try to create the SPI-version only if you have a desparate need for really highspeed-communication between your arduinos.

Eberhard


michel1312

Well. I managed to make my two arduino speak in SPI this works almost fine. The master send data to the slave. The salve don't need to send back soemthign to him.but the trouvle is that I get some 'lost' in the transmission. The lost stop when delaying the master. but not a nice solution.
I just wanna to kno wif it's possible for the master the know when the slave read the data, and for the salve if there is somethign to read. Maybe with the bit settign up the SPI ?

wayoda

Hi,
Quote
Well. I managed to make my two arduino speak in SPI this works almost fine. The master send data to the slave. The salve don't need to send back soemthign to him.but the trouvle is that I get some 'lost' in the transmission.

You found the same problem with SPI-communication that made me turn down that idea.

This issue is solved with I2C-communication using the Wire-Lib, so I'll simply recommend it again.
Good luck
Eberhard
 

bens

Quote
I just wanna to kno wif it's possible for the master the know when the slave read the data, and for the salve if there is somethign to read. Maybe with the bit settign up the SPI ?

There's nothing inherent to the SPI protocol, but you can easily impliment your own solution by connecting an I/O line from the slave to one of the master's I/O lines.  The slave can then use this line to tell you that it needs attention (e.g. it has data ready for you in it's shift register), and the master can either poll this line or set a pin-change interrupt on it.

The reason you need to pause in order to avoid losing data is that every SPI transaction involves two-way data transfer, whether you want it or not.  As data is being sent from the master to the slave, at the same time data is being sent from the slave to the master.  If you send a command to the slave saying "give me data X", you need to actually give the slave enough time to load data X into the shift register before you send your next transmission (and hence receive the data).  If possible, you want to have your slave device implement an SPI-received interrupt so that it can always address such data requests in a timely manner.  You might also consider programming the SPI-received interrupt in assembly to make it maximally efficient/fast, so you know you will never need to delay the master more than so many microseconds before sending the follow-up transmission.

- Ben

Go Up