AnsweredAssumed Answered

SPI receiver register buffer question.

Question asked by miller.mike.003 on Mar 22, 2014
Latest reply on Mar 24, 2014 by miller.mike.003
I am doing an SPI write sending out dummy data to clock in the data from my SPI flash.

  // Dummy data to read status register out
      SPI_SendData8(SPI1, 0x05);
     // Wait until transmit buffer is empty than continue
      while(  !(SPI1->SR & 0x02)  );

At this point I know that the command has been sent out.

The problem is that I am having a hard time determining when to read the data.

For example when I do

received[0] = SPI1->DR;

I don't get the correct value and I seem to be a "cycle" off. When I look in my debugger I can see the value but that is not the one that I have read in.

Should I poll in a similar way as I did in the transmit to know when to read the the receive data register?

I can check the RXNE  (receive buffer not empty bit).
0 = rx buffer empty
1: rx buffer not empty.

// Wait until receive buffer is not empty then read data register
      while(  !(SPI1->SR & 0x01)  );

 received[0] = SPI1->DR;

I tried the above but I am still missing this value. You can see the attached screen shot of my debugger. There are two DR's showing.  The top one (0x00000002) is that value that I am looking for but what I am grabbing from the received[0] = SPI1->DR; command ix 0xFF.

Thanks for any tips.