UncleRus / esp-idf-lib

Component library for ESP32-xx and ESP8266

Home Page:https://esp-idf-lib.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SI7021.c definitions for commands with 2 bytes need bytes reversed

stvnjns opened this issue · comments

The issue

The definitions for the '2 byte commands' in the SI7021 need to be reversed in "si7021.c", as the "i2cdev.c: i2c_dev_read" method is sending 2 byte command out in the reverse order.

The following change allows the serial number and FW_REV to be read correctly. (

Suggested change:

 #define CMD_READ_ID_1                      0x0ffa
 #define CMD_READ_ID_2                      0xc9fc
 #define CMD_READ_FW_REV_1             0xb884

Also added a " si7021_get_device_revision(i2c_dev_t *dev, uint8_t *rev)" for completeness.

In si7021.h:

/**

  • @brief Get device revision
  • This function is supported by:
    • SI7013
    • SI7020
    • SI7021
  • @param dev Device descriptor
  • @param[out] rev Device revision
  • @return ESP_OK on success
    */
    esp_err_t si7021_get_device_revision(i2c_dev_t *dev, uint8_t *rev);

In si7021.c

esp_err_t si7021_get_device_revision(i2c_dev_t *dev, uint8_t *rev)
{
CHECK_ARG( dev || rev);
uint16_t cmd = CMD_READ_FW_REV_1;

I2C_DEV_TAKE_MUTEX(dev);
I2C_DEV_CHECK(dev, i2c_dev_read(dev, &cmd, 2, rev, 1));
I2C_DEV_GIVE_MUTEX(dev);

return ESP_OK;

}

Which SDK are you using?

esp-idf

Which version of SDK are you using?

5.x.x

Which build target have you used?

  • esp32
  • esp32s2
  • esp32s3
  • esp32c2
  • esp8266
  • other

Component causing the issue

si7021

Anything in the logs that might be useful for us?

Current si7021.c definitions result in the serial number being returned a '0x00 ... 0x00'.

Could not find function to read the device revision: Suggest that be added, as shown above.

Additional information or context

No response

Confirmation

  • This report is not a question nor a request for drivers.