Question
Using accelerometer IIS3DWB
Hello all,
I am trying to read the temperature out of the IIS3DWB chip and I am following the github example (iis3dwb_reg.c). My code is given below.
However, once I start running the programme, the temperature I am measuring in degrees Celsius does not make sense at all. I am getting negative values which jump by 10 or 20 degrees every time I resume the programme. Any advice and recommendation would be appreciated.
Best regards,
Kosta
FIND CODE BELOW:
HAL_StatusTypeDef IIS3DWBTR_ReadTemperature(IIS3DWBTR *dev ){
/* Read Raw Values from temperature registers 16bit */
uint8_t regData[2];
HAL_StatusTypeDef status = IIS3DWBTR_ReadRegisters( dev, IIS3DWBTR_OUT_TEMP_L, regData, 2 );
/* Combine register values to give raw (UNSIGNED) temperature readings 16bits */
uint16_t tempRaw;
tempRaw = (uint16_t)(regData[0]<<8 | regData[1]<<0 );
/* Convert to SIGNED integers (two's complement) */
int16_t tempSigned = *(int16_t*) &tempRaw;
/* Convert to deg C */
dev-> temp_C = 0.00390625f * ((float) tempSigned -0.0f) + 25.0f;
return status;
