2025-06-04 8:34 AM
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;
}
2025-06-05 2:42 AM - edited 2025-06-05 2:42 AM
@er3481 wrote:the SGP40 VOC sensor
You mean this: https://sensirion.com/products/catalog/SGP40 ?
Please give details of your hardware; show schematics.
Have you looked at the I2C lines with an oscilloscope and/or analyser to see what - if anything - is happening?
Are you sure you have the correct I2C address, and correctly shifted as HAL requires?