UncleRus / esp-idf-lib

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

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

Closed stvnjns closed 1 year ago

stvnjns commented 1 year ago

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:

/**

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?

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

UncleRus commented 1 year ago

Thank you!