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.

MSP430FR6889: How to store a 24 bit variable?

Part Number: MSP430FR6889


Hello,

I am uisng MSP430FR6889 and BMI160 Sensor. BMI160 has a 24-bit timer counter (BMI datasheet page 53). 

I am trying to store this data but not sure if I am  following the correct procedure.

I have written a I2C function that can access a the I2C slave and start reading from a address and reads till the specified amount of bytes.

I2C_Master_ReadReg(SLAVE_ADDR, 0x18, 3);  //(slave address, Start register address, how many bytes to read)

Then I tried to store the data to a variable but MSP430 is showing me this worning: "64-D shift count is too large". 

Here is that portion of the code:

    uint32_t SENSORTIME;
    uint8_t time_0 = 0;
    uint16_t time_1 = 0;
    uint32_t time_2 = 0;
    
    time_0 = ReceiveBuffer[0];
    time_1 = (uint16_t)(ReceiveBuffer[1] << 8);
    time_2 = (uint32_t)(ReceiveBuffer[2] << 16);
    SENSORTIME = (uint32_t)(time_2 | time_1 | time_0);

I think I know what I am doing wrong here. MSP430 is not a 32-bit MCU. Any suggestion on how to perform this operation?

Thank you.

  • You need to cast the value(s) before doing the shift(s), not after. Unless you need them, I'd dispense with the intermediate variables and use something like:

    > SENSORTIME = ((uint32_t)ReceiveBuffer[2] << 16) | ((uint32_t)ReceiveBuffer[1] << 8) | ((uint32_t)ReceiveBuffer[0] << 0); // Reconstruct value (Little-Endian)

  • Or you could avoid those slow shifts by using a union. That lacks portability (not likely to be an issue) and requires a good knowledge of just how integers are stored.

**Attention** This is a public forum