This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AFE4404EVM: Convert hex data to voltage

Part Number: AFE4404EVM

Hi,

I am using python to read out data from AFE4404EVM. Now, how can I aggregate 3 bytes of data and convert it to the voltage?

Here is my code for it. Is it correct?

my_string =ser.read(22)
#[print(x) for x in my_string]
x=my_string[3]
x+=(my_string[4] << 8)
x+=(my_string[4] << 16)
x=float(x & 0x1111111111111111111111)
x=x*1.2/(2^21)

Thanks,

  • Hi Nam,

    "x+=(my_string[4] << 16)" should have been "x+=(my_string[5] << 16)", here I am assuming that the 3 bytes are stored in my_string[5:3].
    You should also take care of negative numbers by following code.

    if (x>=(2^21)):

    x = x - (2^22) # x can be positive as well as negative number.


    x=x*1.2/(2^21) # In Voltage

    Regards,
    Prabin