Report
1 year, 11 months ago.

Attach interrupt to SPI Slave

I have implemented SPI communication between two LPC11U24 devices. Initially in the code for the slave device I was using the polling method in an RTOS thread to detect an incoming SPI command, and this seemed to work well:

...

SPISlave device(P0_9, P0_8, P1_29, P0_2); 


...


 if(device.receive()) { //if byte has been received from SPI
            char input = device.read();       // Read byte from master
            device.reply('B');              // Will be the reply
            } 

A separate thread running pulse generation was required to be constant. However I soon realised that having multiple threads caused that pulse generation thread to be discontinuous.

So I needed to implement my system based on interrupt driven events rather than threads where the SPI would only be checked if a new SPI command was incoming.

Unfortunately I could not find any simple way of implementing an interrupt based SPI Slave. I had to go for using an extra pin on P1_27 (called SPARE) which would be set by the SPI master prior to an SPI command being sent. This would trigger an SPI interrupt service routing in the SPI Slave which would only be exited once the SPI command had been received:

ISR attatchment

    SPARE.rise(&ISR); // interrupt service routine

ISR

 void ISR()
    {
         while(1)
         {
             if(device.receive())
            {
            char input = device.read();   // Read byte from master
            device.reply('B');          // Will be the reply 
            break;
            }
         }
    }

This works, however is there anyway to attach an interrupt to SPISlave using without the requirement for an extra "interrupt" pin, if so which is the easiest method and are there any examples?

Thanks for any help

Comment on this question

1 Answer

2 months, 1 week ago.

Need to know this too


To post an answer, please log in.