2017-11-02 12:52 AM
Hey guys!
I have an STM32 micro as a Master device, and I am communicating with a slave chip through the SPI interface. It works well, so far I can read from the slave's memory cells, or at least I can see the answer on the oscilloscope. But somehow I'm not able to read out this data from the buffer. I attached the code, I hope somebody can see what I'm missing. I put it in a loop, which quits when theres any data.
#spi2017-11-02 08:08 AM
Naming the device(s) we talk about would surely be helpful.
+1. There should be a 'how to post questions on this forum' FAQ with this being the very first item there.
---
You have to read the bytes out of the Rx buffer even if you don't need them, othewise the SPI receiver overflows (see status register) and stops receiving further bytes. Read the SPI error flags subchapter of the SPI chapter in RM.
Overrun flag (OVR)
An overrun condition occurs when the master or the slave completes the reception of thenext data frame while the read operation of the previous frame from the Rx buffer has notcompleted (case RXNE flag is set).In this case, the content of the Rx buffer is not updated with the new data received. A readoperation from the SPI_DR register returns the frame previously received. All othersubsequently transmitted data are lost.You may have also incorrectly set
JW
2017-11-02 08:55 AM
... as some STM32 devices have a FIFO implementation, ...
Naming the device(s) we talk about would surely be helpful.
To me it seems that spiReceived value equals to the received byte during your transmission of 0x12, and that's why you get the wrong value. Take a look at TXE and RXNE flag timings in the Reference Manual. Wait for another RXNE flag and see if it resolves your issue.
The following dummy-write (0xFE) supposedly clocks out the answer/value.
Perhaps a scope image of a full sequence ?
2017-11-02 10:38 AM
Thanks! As a beginner I completely forgot about optimization. The level is 0 though, and volatile didnt help, but at least wecould rule out this error. Im about to check assembler.
2017-11-02 10:47 AM
That was the problem exactly!! Thank you really, thats just saved me a lot of wasted time. I had to read from the SPI->DR after every transfer, just as you said. And terribly sorry, it's an STM32F103C8T6, I posted this on an other forum where I mentioned the type of the micro, I just copied the body of the message.
2017-11-02 10:53 AM
Surely this was the problem. Funnily I followed the instructions how to conduct the transmission, reception procedure, and the only step I skipped was reading after the rest of the transmissions. Thank you again indeed!