cancel
Showing results for 
Search instead for 
Did you mean: 

Bits sent out from SPI MOSI pin are received inversed by analyzer

GMan1
Associate II

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?

0693W00000JPYTDQA5.png

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

4 REPLIES 4
ssipa.1
Associate II

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.

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.

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

Thank you!