2022-02-12 12:38 AM
Hi!
I am learning to read the stm32f103c8t6 manual in order to be able to control the MCU without the HAL libraries. It seems that I have set up everything as it should be, but the result seems weird. If I write 0x00 to the SPI DR, I see 0x00 by the analyzer. If I write 0xFF to the DR, I see 0xFF by the analyzer. So far everything looks ok, but as soon as I send a value between these two, analyzer receives a value with all the bits inversed:
Sending 0xF0 - receiving 0x0F;
Sending 0x0F - receiving 0xF0;
Sending 0xAA - receiving 0x55;
Sending 0x55 - receiving 0xAA;
Which of the control register parameters could lead to such a result?
Solved! Go to Solution.
2022-02-12 02:56 AM
The bits are not inverted but mirrored. SPI traditionally transmits MSB-first. Try transmitting something like 0x25 to see that.
The SPI module in 'F103 can change the shift orientation by setting SPI_CR1.LSBFIRST, if you need that.
JW
2022-02-12 01:39 AM
Usually, the SPI Master clocks data out while the Slave clocks data back in. So if you were sending and receiving 8 bits per transaction you can clock out 8 bits and at the same time clock in 8 bits for a total of 8 clocks. This is described in this Wikipedia paragraph. That said, often the first 8 clocks are used to transmit a command and an additional 8 clocks are used to retrieve the result.
2022-02-12 01:49 AM
Thanks for your answer. At the moment I have not connected any slave. All I am trying to do is to make sure, that writing from the master works as it should, but the problem is, that I write 0x55 to the DR, but it seems from the analyzer side, that it actually sends 0xAA, so, the binary 0101 0101 becomes 1010 1010. That is my problem at the moment. I have read about the need of the extra empty byte in order to clock in the data from the slave, but I have not got to that point yet.
2022-02-12 02:56 AM
The bits are not inverted but mirrored. SPI traditionally transmits MSB-first. Try transmitting something like 0x25 to see that.
The SPI module in 'F103 can change the shift orientation by setting SPI_CR1.LSBFIRST, if you need that.
JW
2022-02-13 10:51 AM
Thank you!