From d91ad470986417ac912d1c8018f78e710971c590 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 15 Sep 2022 20:30:44 +0800 Subject: [PATCH 1/2] pca9557: Fix base I2C address for TCA9534 According to the datasheet[1], the base I2C address for TCA9534 is 0x20. Table 2. Address Reference A2 A1 A0 I2C BUS SLAVE ADDRESS L L L 32 (decimal), 20 (hexadecimal) L L H 33 (decimal), 21 (hexadecimal) L H L 34 (decimal), 22 (hexadecimal) L H H 35 (decimal), 23 (hexadecimal) H L L 36 (decimal), 24 (hexadecimal) H L H 37 (decimal), 25 (hexadecimal) H H L 38 (decimal), 26 (hexadecimal) H H H 39 (decimal), 27 (hexadecimal) [1] https://www.ti.com/lit/gpn/tca9534 Signed-off-by: Axel Lin --- components/pca9557/pca9557.h | 2 +- examples/pca9557/default/main/Kconfig.projbuild | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/pca9557/pca9557.h b/components/pca9557/pca9557.h index 42a72670..e07a87e5 100644 --- a/components/pca9557/pca9557.h +++ b/components/pca9557/pca9557.h @@ -49,7 +49,7 @@ extern "C" { #define PCA9537_I2C_ADDR 0x49 ///< I2C address for PCA9537 #define PCA9557_I2C_ADDR_BASE 0x18 ///< Base I2C address for PCA9557 -#define TCA9534_I2C_ADDR_BASE 0x38 ///< Base I2C address for TCA9534 +#define TCA9534_I2C_ADDR_BASE 0x20 ///< Base I2C address for TCA9534 /** * Pin modes (directions) diff --git a/examples/pca9557/default/main/Kconfig.projbuild b/examples/pca9557/default/main/Kconfig.projbuild index 5426ec3f..71f95692 100644 --- a/examples/pca9557/default/main/Kconfig.projbuild +++ b/examples/pca9557/default/main/Kconfig.projbuild @@ -12,7 +12,7 @@ menu "Example configuration" PCA9537 has a fixed I2C address (`0x49`). TCA9534 has three address pins (`A0`, `A1` and `A2`). The address - starts from `0x38` (all address pins are grounded) + starts from `0x20` (all address pins are grounded) config EXAMPLE_I2C_MASTER_SCL int "SCL GPIO Number" From 0d33b08a2b6387242358e99332b51fdd1c0603d4 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 15 Sep 2022 20:45:12 +0800 Subject: [PATCH 2/2] pca9557: Fix pca9557_get_mode/pca9557_set_mode The read_bit() and write_bit() do not read/write correct register in current code, fix it. This fixes pca9557_get_mode() and pca9557_set_mode(). Signed-off-by: Axel Lin --- components/pca9557/pca9557.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/pca9557/pca9557.c b/components/pca9557/pca9557.c index f31552cc..8325e677 100644 --- a/components/pca9557/pca9557.c +++ b/components/pca9557/pca9557.c @@ -75,7 +75,7 @@ static esp_err_t read_bit(i2c_dev_t *dev, uint8_t reg, uint8_t bit, uint32_t *va CHECK_ARG(dev && val); uint8_t v; - CHECK(read_reg_8(dev, REG_IN, &v)); + CHECK(read_reg_8(dev, reg, &v)); *val = v & BIT(bit) ? 1 : 0; return ESP_OK; @@ -88,9 +88,9 @@ static esp_err_t write_bit(i2c_dev_t *dev, uint8_t reg, uint8_t bit, uint32_t va uint8_t v; I2C_DEV_TAKE_MUTEX(dev); - I2C_DEV_CHECK(dev, i2c_dev_read_reg(dev, REG_OUT, &v, 1)); + I2C_DEV_CHECK(dev, i2c_dev_read_reg(dev, reg, &v, 1)); v = (v & ~BIT(bit)) | (val ? BIT(bit) : 0); - I2C_DEV_CHECK(dev, i2c_dev_write_reg(dev, REG_OUT, &v, 1)); + I2C_DEV_CHECK(dev, i2c_dev_write_reg(dev, reg, &v, 1)); I2C_DEV_GIVE_MUTEX(dev); return ESP_OK;