Altera_Forum
Honored Contributor
12 years agoSPI slave code
Hi,
I'm using the QSYS SPI module as a slave. The SPI slave is supposed to receive sequences of bytes/characters. In order to make this happen, I'm using some SW code that reads the status register and checks that the RRDY (receive ready) bit is set. When the RRDY is set, I read from the rxdata register and store the byte in a array. The problem that I'm having is that I'm only reading a single byte/character at a time. I would like to fill up the array with the whole sequence being transmitted from the external SPI master. What's happening is that after reading the first byte (reading from the rxdata register clears the RRDY bit), I' getting stuck waiting for the RRDY bit to be asserted for the next byte/character. If I try to re-send the command sequence, the RRDY bit triggers, but again I'm only reading a single byte, and the same thing happens. The SW code I'm using: IORD_ALTERA_AVALON_SPI_RXDATA(SPI_BASE); for ( ;; ){printf("\n================================================\n");
printf("Wait until the RRDY bit in the status register triggers \n");
do { status = IORD_ALTERA_AVALON_SPI_STATUS(SPI_BASE); } while ((status & ALTERA_AVALON_SPI_STATUS_RRDY_MSK) == 0);
if ((status & ALTERA_AVALON_SPI_STATUS_RRDY_MSK) != 0) { alt_u32 rxdata = IORD_ALTERA_AVALON_SPI_RXDATA(SPI_BASE); //Reading the rxdata register clears the RRDY bit in the status reg. *read_data++ = (char)rxdata;//Store the received bytes if ((char)rxdata == '(') //end of command byte { *read_data++ = '\0'; break; } } }