2024-02-03 11:13 AM - edited 2024-02-04 09:50 AM
Hi all,
I'm currently not able to read the temperature of my lis2de12.
It always returns zero.
lis2de12_temperature_meas_set(&dev_ctx, LIS2DE12_TEMP_ENABLE);
lis2de12_data_rate_set(&dev_ctx, LIS2DE12_ODR_400Hz );
lis2de12_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);
What could be the issue here?
I'm only reading temp, not X Y Z values yet.
UPDATE:
After playing around reading OUT_TEMP_L (0Ch), OUT_TEMP_H (0Dh) separately, my code now reads twice 0x80.
I think my platform functions are not incrementing the register address?
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, uint16_t len)
{
HAL_I2C_Mem_Read(handle, LIS2DE12_I2C_ADD_H, reg, 1, (uint8_t*)bufp, len, 1000);
return 0;
}
Otherwise I would assume seeing 0x0D in the scope image.
2024-02-05 02:49 AM
Hi @WSpar.1 ,
Please, look at our drivers on github where you can find how to implement the reading of the temperature.
Let me know if this helps.
2024-02-05 08:33 AM
I'm using that driver, it works fine for reading single register, not if you need incremental register address 0x0C to 0x0D
The working depends on what is inside platform_read()
For now I fixed it with, but not ideal:
static int32_t platform_read(void *handle, uint8_t reg, uint8_t *bufp, uint16_t len)
{
if(len == 2)
{
HAL_I2C_Mem_Read(handle, LIS2DE12_I2C_ADD_H, reg, 1, (uint8_t*)bufp, 1, 1500);
reg++;
bufp++;
HAL_I2C_Mem_Read(handle, LIS2DE12_I2C_ADD_H, reg, 1, (uint8_t*)bufp, 1, 1500);
} else {
HAL_I2C_Mem_Read(handle, LIS2DE12_I2C_ADD_H, reg, 1, (uint8_t*)bufp, len, 1500);
}
return 0;
}
Would be nice if HAL_I2C_Mem_Read() had an register increment option
2024-03-04 05:02 AM
Hi @WSpar.1 ,
You can look here how to implement the read/write multiple.
You will find this comment: /* Read multiple command */ and how to implement it in I2C communication.
Hope this helps.