Recently i'm getting things done with i2c and i have successfully wrote/read other pheripherals with this configuration and functions.
Yesterday i discovered that my micro usb (that i use for debug) would cut off connection whenever i tried to write any number in the xl9555 registers that is between 0 and 7, each time i had to turn off the board and then turn it on with the boot button pressed so i could see the usb again with my operating system (windows 11) and put other firmware.
With "cut off" i mean that the usb was literally invisibile as if the cable didn't exist.
I think this is because the xl9555 needs to have a command byte that is always a value between 0 and 7, so for example:
XL9555 ADDRESS COMMAND BYTE DATA
0010 0000 0000 0110 0000 0100
The bus is written with these values, in this example, we write in the register 6 of the xl9555 with the value of 4, the micro usb would cut off and i couldn't see my esp32 no more.
However, the data is correcly written in the register in fact i could use xl9555 i/o with my firmware to play and stop buzzer or to turn on leds.
The problem is that i don't understand the behaviour of the micro-USB , why does it do like that? and why only with these specific values? Maybe i'm using wrong the library functions?
I tested the hardware and it seems ok, i could simply ignore the fact that i can't use 8 of 256 possible configurations and go on with other pin configurations for i/o, but i want to understand why does this happen and if it is a problem with my code or with library code.
Thank you in advance!
hardware:
- esp32-s3
- xl9555 (https://datasheet.lcsc.com/lcsc/2103251 ... 609791.pdf)
firmware:
Code: Select all
// init master
static esp_err_t i2c_master_driver_initialize(void)
{
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = i2c_gpio_sda,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_io_num = i2c_gpio_scl,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = i2c_frequency,
// .clk_flags = 0, /*!< Optional, you can use I2C_SCLK_SRC_FLAG_* flags to choose i2c source clock here. */
};
return i2c_param_config(i2c_port, &conf);
}
// i2c write
static esp_err_t write_slave_pheripheral(uint8_t pheripheral_address, uint8_t reg_addr, uint8_t data)
{
int ret;
uint8_t write_buf[2] = {reg_addr, data};
ret = i2c_master_write_to_device(i2c_port, pheripheral_address, write_buf, sizeof(write_buf), I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
return ret;
}
void app_main(void)
{
// init i2c
ESP_ERROR_CHECK(i2c_driver_install(i2c_port, I2C_MODE_MASTER, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0));
ESP_ERROR_CHECK(i2c_master_driver_initialize());
// i2c writes causing errors
//ESP_ERROR_CHECK(write_slave_pheripheral(XL9555_ADDRESS, 0x06, 0)); // 0000 0000
//ESP_ERROR_CHECK(write_slave_pheripheral(XL9555_ADDRESS, 0x06, BIT0)); // 0000 0001
//ESP_ERROR_CHECK(write_slave_pheripheral(XL9555_ADDRESS, 0x06, BIT1)); // 0000 0010
//ESP_ERROR_CHECK(write_slave_pheripheral(XL9555_ADDRESS, 0x06, BIT0 | BIT1)); // 0000 0011
//ESP_ERROR_CHECK(write_slave_pheripheral(XL9555_ADDRESS, 0x06, BIT2)); // 0000 0100
//ESP_ERROR_CHECK(write_slave_pheripheral(XL9555_ADDRESS, 0x06, BIT0 | BIT2)); // 0000 0101
//ESP_ERROR_CHECK(write_slave_pheripheral(XL9555_ADDRESS, 0x06, BIT1 | BIT2)); // 0000 0110
//ESP_ERROR_CHECK(write_slave_pheripheral(XL9555_ADDRESS, 0x06, BIT1 | BIT2 | BIT0 )); // 0000 0111
}