cancel
Showing results for 
Search instead for 
Did you mean: 

LIS3DH sensor - Required method / formulae to convert the Raw ADC value to Temperature

Surya S
Associate II

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.  

  1. Configured the sensor registers as per the data sheet(attached here for your reference).

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.

SuryaS_0-1705043256617.png

SuryaS_3-1705043798452.png

 

   2. To convert the Temperature sensor output value to temperature conversion – the below is the table given in the data sheet.

SuryaS_2-1705043256634.png

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, &reg, 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, &reg, 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

 

2 REPLIES 2
Federica Bossi
ST Employee

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.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
Federica Bossi
ST Employee

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.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.