UncleRus / esp-idf-lib

Component library for ESP32-xx and ESP8266
https://esp-idf-lib.readthedocs.io/en/latest/
1.37k stars 426 forks source link

sgp40: Invalid CRC 0x31, expected 0xfe #517

Closed Ether-YiTseWu closed 1 year ago

Ether-YiTseWu commented 1 year ago

The issue

Connect Sparkfun SGP40 air quality sensor to ESP32, run the code below, and the error likes that

[0;31mE (2603) i2cdev: Could not read from device [0x45 at 1]: 263 (ESP_ERR_TIMEOUT)
[0;31mE (2623) sgp40: Invalid CRC 0x31, expected 0xfe
ESP_ERROR_CHECK failed: esp_err_t 0x109 (ESP_ERR_INVALID_CRC) at 0x400d6fbc
file: "./main/HygroX.c" line 130
func: initSGP40
expression: sgp40_init(&sgp)

Which SDK are you using?

esp-idf

Which version of SDK are you using?

5.0.1

Which build target have you used?

Component causing the issue

SGP40

Anything in the logs that might be useful for us?

My program : 

sgp40_t initSGP40()
{
    sgp40_t sgp;
    memset(&sgp, 0, sizeof(sgp));
    ESP_ERROR_CHECK(i2cdev_init());
    ESP_ERROR_CHECK(sgp40_init_desc(&sgp, 0, I2C_MASTER_SDA, I2C_MASTER_SCL));
    ESP_ERROR_CHECK(sgp40_init(&sgp));
    ESP_LOGI(TAG, "SGP40 initilalized. Serial: 0x%04x%04x%04x",
            sgp.serial[0], sgp.serial[1], sgp.serial[2]);
    return sgp;
}

void app_main(void)
{
    float T = 25, RH = 50;
    sgp40_t sgp = initSGP40();
    ESP_ERROR_CHECK(sgp40_measure_raw(&sgp, RH, T, &voc));
}

Additional information or context

No response

Confirmation