I'm trying to write code for a SPI slave device that reads data from the MISO line.
Here is the register map for the SPI device.

Basically my code looks at the status register and checks two conditions.
Is the
RRDYbit set? (which indicates that there is data in the RX register)Is the
ROEbit not set? (which indicates that recieve over-run error has not occured)
If these conditions are met then I put the recieved char into the array buf.
I am sending the device the characters 'A', 'B' and 'C'.
When I recieved 'C' I break the loop and then print out the contents of `buf'.
My question is, buf only contains 'C', '0', '0'.
Is there something wrong with my logic?
char ibuf[32];
int chr;
int ptr;
while(1) { //keep checking
//if RRDY set and ROE is not 1
if (((*spi_status_reg >> 7) & 1) && (!(*spi_status_reg >> 3) & 1)) {
//macro to read char from the rx register
chr = IORD_ALTERA_AVALON_SPI_RXDATA(SPI_1_SLAVE_BASE);
ibuf[ptr] = chr; // store it
ptr ++;
//if 'C' then exit
if(chr == 'C') {
printf("Got C\r\n");
break;
}
}
}
printf("Exit\r\n");
for (int i= 0; i<3; i++) {
printf("Buffer %x\r\n", ibuf[i]);
}