cancel
Showing results for 
Search instead for 
Did you mean: 

How to transmit hex data over spi?

Dian.1
Associate II

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.

3 REPLIES 3

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
Up vote any posts that you find helpful, it shows what's working..
TDK
Guru

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
Associate II

@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?