cancel
Showing results for 
Search instead for 
Did you mean: 

convert 10-bit data uint10_t to float

StanCosgrove
Associate II

i m using STM32H7 SPI to interface to external 10-bit ADC, which return a 16-bit data but only the last 10 bit (from LSB) is valid. How can i convert this 10-bit data to float ? and how can i obtain these 10-bit from the 16 bit data, i know i would need t0 shift left 10 (<<10) , anyone can advise?

D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0

X     X      X     X     X      X    1   0     1    0   1    1    0    1   1    0

uint10_t Real_data; // valid statement?

Real_data = (SPI_rx <<10);

ADC_out = float(Real_data);

3 REPLIES 3

Shift it by 10 ? You sure? What's the byte order?

ADC_out= (float)(SPI_rx & 0x3FF); // mask the low order unsigned bits and cast

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

ok thx, but is the uint10_t valid ?? never seen this in any code...

cancel last...