AnsweredAssumed Answered

SPI communication two MCUs - bitshift

Question asked by heil.janis on Aug 12, 2016
Latest reply on Aug 12, 2016 by heil.janis

I want to transmit and receive data between two STM32F401RE NUCLEO boards. Performance does not matter, so the simplest approach seems to be using the blocking HAL_SPI_TransmitReceive(..) function on both sides.

One board is setup as master, one as slave, code and config are generated via CubeMX. I am pretty sure to have a correct wiring (using the same setup for SPI-bootloader communication with hardly any problems).

The strange thing is that when I debug the code on the master, I receive a bit-shifted version of the data that I send on MISO.
Example: I send 0xA6 on the slave, but I receive 0x9A (same byte shifted by 2 bits) on the master.

This shift occurs randomly with each reboot of the MCU and then stays persistent. So if the shift once is 2 bits, it stays 2 bits even when I resend the byte many many times. When I reset the master MCU, the shift differs randomly.

Do I have to flush something prior to communication?
What else could I do wrong? (CPOL and all other settings are the same on master/slave.)

Thanks for the help :)