communicating via spi

A couple of questions..

Lets say I have two devices connected via spi, like a nRF24L01 and an Arduino NANO.

When there is no activity, does the clock continue to run, or does the clock start when one or the other needs to send data. A related question is does either one have to be the master at all times or is the master the one that initiates the transfer regardless of whether it is the Nano or the nRF.

I am guessing that when either one needs to send data, then the device starts the clock, lowers the CE pin, and then sends data out of the MSIO (or is it the MISO) port. Once the transfer is complete, the the device can initiate another transfer or wait until to other device starts a transfer.

In the World of Master and Slaves it usualy very well defined who is the master. Ethernet communication works differently. Anybody can grabb the line and start sending at any time. A protocol handles collisions.

I am asking about the SPI interface between the NANO and the nRF24l01 not ethernet.

I have tried to understand the SPI documentation and I have put a scope on the signal lines and still have a question.

The SPI document says that there is a master and a slave. However, when I want to communicate between the NANO and the nRF, it seems to me that either one can be the master depending on which device has data to transfer. If for example the nRF has received a message, then it seems to me that the nRF must initiate the transfer to the NANO. On the other hand, if the NANO wants to send a message, then it must initiate the transfer.

The SPI documentation I have read simply says there is one master and possible a number of slaves. If this is the case and we assume the NANO is the master, then how would the nRF ever get to send data to the NANO?

??

I'm not at all an expert but my standpoint is that it is well defined from start who is the Master, and which ones are Slaves. Changing this dynamically sounds strange to me.
One of the responcibilities of the Master would be to call the Slaves and check for messages if they are used to produce data.

A slave cannot initiate an SPI transfer, only the master can do that.
So, first, the slave has to grab the master's attention.

Now, what mechanisms have we got to achieve this?

"Now, what mechanisms have we got to achieve this?"

I would assume that the slave could wiggle either the CE or the CSN line. Not sure which. Once the master get the attention, then does the master start up the clock and for how long?

No, the master can ask the slave "have you got anything for me?" or the slave can interrupt the master.

No, the master can ask the slave "have you got anything for me?" or the slave can interrupt the master.

I understand what you are saying but this seems a bit strange. Lets say I have a NANO connected to a sensor and the sensor triggers one time a day. Does the master have to keep querying the sensor all day long? I guess doing the interrupt thing would be better.

Then, assuming we use the interrupt, how would the master know how much data the slave(sensor) has to transmit? Does the master then ask the slave how much data and then turn on the clock for a sufficient length of time(bytes)?

Why is it "strange"?
Has the Nano got anything better to do?

how would the master know how much data the slave(sensor) has to transmit?

By asking the slave.

In my NANO/nRF example, the interrupt is not used so I guess the nRF driver in the NANO must have some default rate at which it queries the slave. If the nRF receives a lot of data between queries, then it seems that there could be a data overrun or loss. For now, I guess I will have to trust the driver software.

Typically the Master knows how much data to read because either the data length is fixed or the data contains a fixed header that says how much more data is coming. The RF24L01 datasheet will say how the Master interacts with it.

…. Either You use a standard protocol between the Master and the Slave, or You design Your own. The first question from the Master could be: "How many bytes". Then the Master has to be prepared for interpreting a varying amount of bytes. Or, You have a static amount of data in each transmission, filled out with blanks, whatever You choose.
Interrupts? How? From where? It calls for a self made communication it looks like to me.

Why not query? Just choose the intervall in a way that gives the master time to do what it needs to do.

I guess the nRF driver in the NANO must have some default rate at which it queries the slave

Normally, your program calls the driver to check whether the receiver has characters available.

If the Nano must be doing other things as well, use the interrupt to inform the Nano that data are ready.

You have the code, take a look at it.