cancel
Showing results for 
Search instead for 
Did you mean: 

Reading SPI port - first byte?

vince
Associate III
Posted on April 08, 2014 at 16:53

Maybe some of you with SPI experience can spot this one easily. I have a SPI slave device connected to my STM8L152. I watch the clock and data stream to the device requesting a read of a register, and then I can see the proper bit stream returned on the MISO line. However, I cannot get the STM8L's RX buffer to read the thing correctly. In fact, it rarely changes no matter what the bit pattern I see on the line. I have tried both phase polarities, and I am confident the clock polarity should be ''idle low''. Here is the short section of code, using only standard library calls, following the protocol as I understand it to be from the User's Manual (pg 549, ''full duplex''). I break on a line following the last and read the returned result. Any suggestions are welcome. Thanks.

 //send byte through the SPI peripheral

  SPI_SendData(SPI1, 0x42);

    //loop while DR register in not empty

  while (SPI_GetFlagStatus(SPI1, SPI_FLAG_TXE) == RESET);

    

    //send redundant byte through the SPI peripheral (clocks in response to first read)

  SPI_SendData(SPI1, 0x42);

    //wait to receive a byte

  while (SPI_GetFlagStatus(SPI1, SPI_FLAG_RXNE) == RESET);

  // Return the byte read from the SPI bus

  spiByte = SPI_ReceiveData(SPI1);

#spi
1 REPLY 1
jamiliang
Associate
Posted on September 18, 2015 at 10:22

Hi, the problem of MISO is missing data that Larger than 0X80, it means if First Bit is 1,then STM8S will ''ignore'' it!(miss 0x8F, but get 0x7F!)

I still can't understand WHY!

Because I try that device to STM32 is fine!