Question
SGP40 sensor
Hi
I am trying to read the SGP40 VOC sensor with the code below, but i can't read the raw data. I can transmit the command but when i try to receive data, it can not receive. I am using STM32F103 mcu. Any advise .
uint8_t SGP40_ReadVOC(void)
{
uint8_t cmd[2] = {0x26, 0x0F};
uint8_t rx_buf[6];
uint16_t voc_raw = 0;
HAL_Delay(250);
if (HAL_I2C_Master_Transmit(&hi2c1, 0xB2, cmd, 2, HAL_MAX_DELAY) != HAL_OK)
{
return 0xFF;
}
HAL_Delay(30);
if (HAL_I2C_Master_Receive(&hi2c1, 0xB3, rx_buf, 6, HAL_MAX_DELAY) != HAL_OK)
{
return 0xFF;
}
voc_raw = (rx_buf[0] << 8) | rx_buf[1];
return voc_raw >> 8;
}
