Skip to main content
Dian.1
Associate
June 27, 2021
Question

How to transmit hex data over spi?

  • June 27, 2021
  • 3 replies
  • 1640 views

I want to transfer binary data (not character) without having to worry about character conversion, so directly:

uint8_t data = 0xBF;

HAL_SPI_Transmit(&spi1handle, (uint8_t *) data, 1, 1000);

But I get something else at the receive end, specifically I get for example 0xDC so not the same data that I send. As a beginner I would like to know how I can make the above work.

This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
June 27, 2021

This was the correct approach.

You need to double check clocking and phase options at both ends.

>>But I get something else at the receive end. 

Unfortunately you don't state what. Perhaps shifted one bit left or right?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
TDK
June 27, 2021

Note that SPI needs a method to synchronize bytes, typically through use of a CS pin.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Dian.1
Dian.1Author
Associate
June 27, 2021

@Community member​ @TDK​ Do I need to do something with the bits at the receive ends? I expect that if I send 8 bits which is 0xBF , I receive those 8 bits (configured it for 8 bits data). I will try again, how can I best debug this kind of problem?