Skip to main content
timothy0508
Associate II
Oct 16, 2020 8:05 AM UTC
Solved

LIS2DE12 I2C write timeout

My application is very low power, and I need to save power wherever possible.

To this end, I do the following:

LIS2DE12_WriteReg(LIS2DE12_MEMS_I2C_ADDRESS, 0x20, 0x08);

Which basically puts the accelerometer in power down mode. The LIS2DE12_WriteReg basically uses HAL_I2C_Mem_Write.

I seem to constantly get a HAL_TIMEOUT returned whenever I try to put the accelerometer in power down mode. I even set the timeout to a high value, and its still the same problem.

Inside LIS2DE12_WriteReg , this is what happens:

HAL_StatusTypeDef i2c_write_status;
 
i2c_write_status = HAL_I2C_Mem_Write(&hi2c1, deviceAddress, WriteAddr, I2C_MEMADD_SIZE_8BIT, (uint8_t*)&Data, 1, 10000);
 
DEBUG_LOG_ACC("I2C Bus Status(A): %d", HAL_I2C_GetError(&hi2c1));
DEBUG_LOG_ACC("I2C Write Status(A): %d", i2c_write_status);

i2c_write status always returns HAL_TIMEOUT.

Thanks for your time.

Tim

    This topic has been closed for replies.
    Eleon BORLINI
    Eleon BORLINIBest answer
    ST Employee
    Oct 16, 2020 2:56 PM UTC

    Hi @timothy0508​ ,

    not sure you have to write the LPen bit in CTRL_REG1 (20h) register: this bit enables the Low Power mode, and not the Power down mode, which is enabled by the ODR <3:0> = 0000 bin. Can you try to write 00h in the register and check if you still get the HAL_TIMEOUT error?

    -Eleon

    4 replies

    Eleon BORLINI
    Eleon BORLINIBest answer
    ST Employee
    Oct 16, 2020 2:56 PM UTC

    Hi @timothy0508​ ,

    not sure you have to write the LPen bit in CTRL_REG1 (20h) register: this bit enables the Low Power mode, and not the Power down mode, which is enabled by the ODR <3:0> = 0000 bin. Can you try to write 00h in the register and check if you still get the HAL_TIMEOUT error?

    -Eleon

    Eleon BORLINI
    ST Employee
    Oct 22, 2020 11:41 AM UTC

    Hi Tim,

    did you make some progression on your issue?

    -Eleon

    timothy0508
    Associate II
    Nov 1, 2020 12:01 AM UTC

    Hi Eleon

    Thanks for checking in. Yes. It turned out there was a hardware pin that controlled the accelerometer. At some specific point in the program, the accelerometer had been accidentally turned off - which explained the timeout error.

    Tim