Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Honored Contributor I
655 Views

SPI Slave multi-byte transfers

Hello, 

I am trying to receive a 9 byte length SPI message with standard Altera SPI slave component in QSys. I need to use interrupts, since I can't poll for packets in the main cycle. All 9 bytes are transferred by the master during one chipselect toggle. If I'm sending only one byte, then everything work fine. 

 

Here's my interrupt routine: 

void SPI_ISR(void * context) { DISABLE_INTERRUPTS(); IOWR_ALTERA_AVALON_SPI_STATUS(SPI_BASE, 0x00); // Clear status register spi_rx_value = IORD_ALTERA_AVALON_SPI_RXDATA(SPI_BASE); for(spi_index=1; spi_index<9; spi_index++) { while((IORD_ALTERA_AVALON_SPI_STATUS(SPI_BASE) & ALTERA_AVALON_SPI_STATUS_RRDY_MSK) == 0); spi_rx_value = IORD_ALTERA_AVALON_SPI_RXDATA(SPI_BASE); } ENABLE_INTERRUPTS(); }  

 

As You can see, I get interrupt on the very first byte and poll other 8 bytes of data. 

 

The problem: 

I constantly get program stuff in a while() cycle waiting for the byte to be received. It gets stuck in random place: sometimes I see spi_index=5, sometimes spi_index=1. If I do data retransfer, then this routine gets completed and a byte from the middle of the second message triggers another interrupt. This causes complete mess.  

 

What I am doing wrong here? 

 

Thank You.
0 Kudos
0 Replies