Interrupt in SPI

Thread Starter

sarvanan

Joined Aug 8, 2016
45
Hi Members,

While communicating between PIC and another microcontroller using SPI, Do PIC (Master) need to generate an Interrupt necessarily to another microcontroller (Slave) and then start SCK, SDO, SDI lines? Or PIC just need to check when slave is ready then start communication?

Thanks & regards,
Sarvanan.
 

nsaspook

Joined Aug 27, 2009
16,322
The slave's should always be ready for communication unless they are executing a critical sequence initiated from the master. Normally the master would send commands to a slave with pre-timed slave processing delay/timeout(s) between commands/data reads if the slave needs significant processing time (like ADC conversion time) for a command. An interrupt from the slave to the master could then preempt the total delay to the actual time needed for the command to execute causing the master to request data from the slave quicker if using interrupt driven feedback.
 
Last edited:

jpanhalt

Joined Jan 18, 2008
11,087
While the master can force communication with the slave, that communication may not be fruitful when the slave is doing something. For some sensors, e.g., inertial and magnetic sensors, a forced read can interrupt an on-going read and return either corrupt data or (more likely) old data.

In the devices mentioned, the slave will almost certainly have something like a "ready" signal or bit in a status register when data are ready to be read. When it is a signal, it takes another wire, but is easy to deal with. "DRDY" seems to be a common label that is used for that signal. When it is a bit in a status register, then you do have to write an address and do a read, but that is a lot better than disrupting a data read or corrupting the data.

Those comments do not apply to all devices. Data sheets for the slave will explain what applies.

John
 

NorthGuy

Joined Jun 28, 2014
611
Usually CS or SS line is used to "activate" the slave. Each slave has its own CS while SCK, MOSI, and MISO are shared. The master selects the particular slave by dropping its CS low. The slave responds by driving the MISO low and then waits for the CLK line. Once the communication is over, the master pulls CS high. In response, the slave deactivates the MISO line so that the other slaves could drive it.

That's the theory. In practice, every device has its own peculiarities you need to obey. So, read the datasheet.
 

dannyf

Joined Sep 13, 2015
2,197
Do PIC (Master) need to generate an Interrupt
It is not clear that you understand what an interrupt is - to out it politely.

It seems that you are talking about external interrupt as a way for the slave to notify the master for transmission.

As I already pointed out to you, that is an extremely unusual setup - I have never seen one - and very counter intuitive.

With that said, interrupts (of other types) are widely used in data transmission, spi or otherwise. Especially for low baud rate spi on a fast MCU, you cannot wait for the spi transmission to finish. Thus using an interrupt (not external interrupt) is the only way to go.

You need to read a few data sheets to understand how this may work.
 

jpanhalt

Joined Jan 18, 2008
11,087
It is not clear that you understand what an interrupt is - to out it politely.

It seems that you are talking about external interrupt as a way for the slave to notify the master for transmission.

As I already pointed out to you, that is an extremely unusual setup - I have never seen one - and very counter intuitive.
If you include in the term, "transmission" to initiate a read, it is not so uncommon in my very limited experience. The BMC156 does exactly that with the DRDY ("device ready") line. It is not held constantly active, so it has to be treated by the master as an interrupt. I have not dealt with 100's of different devices, but for the half dozen or so devices I have done, it would not seem to be rare or counter intuitive. A "ready" line basically makes a 5- or 4-wire wire interface from a 4- or 3-wire interface, respectively.

John
 
Top