Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12367 Discussions

SPI Slave multi-byte transfers

Honored Contributor I


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