2024-01-11 11:23 PM
Hello Everyone,
Kindly provide the details of raw sensor data interpretation method/ formulae to equate for getting the required data
The following are the steps executed.
As per the below block diagram the temperature sensor is connected via ADC3 channel higher register, so able to read the raw temperature adc value from this register.
2. To convert the Temperature sensor output value to temperature conversion – the below is the table given in the data sheet.
Find the code :
void int_LIS3DHtemp(void)
{
uint8_t ADSwrite[2] = "0";
uint8_t address = ADDRESS;
uint8_t lowByte;
uint8_t SampleCount;
HAL_StatusTypeDef status;
ADSwrite[0] = CTRL_REG_4; ///CTRL_REG_1;/* 0100 00xx*/
ADSwrite[1] = 0x80;
if (HAL_I2C_Master_Transmit(&hi2c2, address << 1, ADSwrite, 2, I2C_HAL_API_TIMEOUT) != HAL_ERROR)
{
}
ADSwrite[0] = CTRL_REG_4; ///CTRL_REG_1;/* 0100 00xx*/
ADSwrite[1] = 0x82;
if (HAL_I2C_Master_Transmit(&hi2c2, address << 1, ADSwrite, 2, I2C_HAL_API_TIMEOUT) != HAL_ERROR)
{
}
ADSwrite[0] = CTRL_REG_4; ///CTRL_REG_1;/* 0100 00xx*/
ADSwrite[1] = 0x00;
if (HAL_I2C_Master_Transmit(&hi2c2, address << 1, ADSwrite, 2, I2C_HAL_API_TIMEOUT) != HAL_ERROR)
{
}
HAL_Delay(20);
ADSwrite[0] = CTRL_REG_4; ///CTRL_REG_1;/* 0100 00xx*/
ADSwrite[1] = 0x80;
if (HAL_I2C_Master_Transmit(&hi2c2, address << 1, ADSwrite, 2, I2C_HAL_API_TIMEOUT) != HAL_ERROR)
{
}
}
uint32_t readLIS3DHtemp(void)
{
uint8_t ADSwrite[ADC_CHANNELS_USED] = "0";
uint8_t address = ADDRESS;
uint8_t reg;
uint8_t highByte;
ADSwrite[0] = 0x1f;
ADSwrite[1] = 0xC0; //TEMP_CFG_REG;
if (HAL_I2C_Master_Transmit(&hi2c2, address << 1, ADSwrite, 2, 1000) == HAL_OK)
{
if (HAL_I2C_Master_Receive(&hi2c2, address << 1, ADSread, 2, 1000) != HAL_OK)
{
SensorReadingAndCal.codeStatus = eI2C_COMMUNICATION_ERROR;
AddErrorLog(&SensorReadingAndCal);
}
}
reg = 0X0C;
if (HAL_I2C_Master_Transmit(&hi2c2, address << 1, ®, 1, I2C_HAL_API_TIMEOUT) != HAL_ERROR)
{
if (HAL_I2C_Master_Receive(&hi2c2, address << 1, &lowByte, 1, 1000) != HAL_OK)
{
}
}
reg |= 0x01;
if (HAL_I2C_Master_Transmit(&hi2c2, address << 1, ®, 1, I2C_HAL_API_TIMEOUT) != HAL_ERROR)
{
if (HAL_I2C_Master_Receive(&hi2c2, address << 1, &highByte, 1, 1000) != HAL_OK)
{
}
}
}
Able to read the data in the OUT_ADC3_HIGH(0Dh) register. The value read from the
register is 7. But my room temperature is 24.7°C.
What is the offset value or any process has to be done to get the actual temperature value.
Thanks in advance
Surya S
2024-01-19 12:18 AM
Hi @Surya S ,
I suggest you to have a look at our drivers on github. You will find all the functions concerning temperature data generation so that you can check your code for errors.
Let me know if this helps.
2024-02-01 01:11 AM
Hi @Surya S ,
Have our drivers helped you?
If yes, remember to flag my answer as "Accept as solution" so that it can help other users.