Strange microUSB behaviour with ESP32-S3 I2C and XL9555 (lib v5.0)

MasterExploder
Posts: 24
Joined: Wed Feb 08, 2023 6:17 pm

Strange microUSB behaviour with ESP32-S3 I2C and XL9555 (lib v5.0)

Postby MasterExploder » Wed Feb 08, 2023 7:37 pm

Hi all, i would like to ask help to anyone who has an idea of what is happening here.

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
}

ESP_Sprite
Posts: 8884
Joined: Thu Nov 26, 2015 4:08 am

Re: Strange microUSB behaviour with ESP32-S3 I2C and XL9555 (lib v5.0)

Postby ESP_Sprite » Thu Feb 09, 2023 12:19 am

That is a very strange issue. Do you have a schematic of what you're trying to build? (If you're prototyping, just tell us what devboard you're using and what connections you're making.)

MasterExploder
Posts: 24
Joined: Wed Feb 08, 2023 6:17 pm

Re: Strange microUSB behaviour with ESP32-S3 I2C and XL9555 (lib v5.0)

Postby MasterExploder » Thu Feb 09, 2023 10:22 am

Here you are.
LC-HMI-S3 FULL-pages-1,4,6,9.pdf
(1.05 MiB) Downloaded 235 times

ESP_Sprite
Posts: 8884
Joined: Thu Nov 26, 2015 4:08 am

Re: Strange microUSB behaviour with ESP32-S3 I2C and XL9555 (lib v5.0)

Postby ESP_Sprite » Fri Feb 10, 2023 2:11 am

Just to check: you're debugging through J11? I also see that the XL9555 is switching some power supplies; could it be that one of those gets switched when you write to it, putting e.g. EMC on the power lines? Also, can you check what the debug UART (J20) says when this happens; do you get some kind of error on there?

MasterExploder
Posts: 24
Joined: Wed Feb 08, 2023 6:17 pm

Re: Strange microUSB behaviour with ESP32-S3 I2C and XL9555 (lib v5.0)

Postby MasterExploder » Sun Feb 12, 2023 8:39 am

Yes i am debugging through J11.

Yes the XL9555 is switching some power supplies but the only pins that are giving problems are the pins P00, P01, P02 when all other pins are zero; As i said before, the problem emerges if the configuration reppresent a number between 0 and 7, in my case the desired configuration is the following: 0 0 0 0 0 1 0 0, because i only have one pin (the pin P02) that works as an input (in the scheme you will se also another pin (P03) that works as an input, but i it is a typo, in fact it is an output pin).

The debug UART (J20) is correcly working.

Thank you for your help

ESP_Sprite
Posts: 8884
Joined: Thu Nov 26, 2015 4:08 am

Re: Strange microUSB behaviour with ESP32-S3 I2C and XL9555 (lib v5.0)

Postby ESP_Sprite » Sun Feb 12, 2023 2:20 pm

So do you see anything on the serial UART when this happens? Also, can you check if it's really not the XL9555 IO by, for example, disconnecting those power pins and connecting them 'hard' to the desired levels so the ESP can't influence them?

MasterExploder
Posts: 24
Joined: Wed Feb 08, 2023 6:17 pm

Re: Strange microUSB behaviour with ESP32-S3 I2C and XL9555 (lib v5.0)

Postby MasterExploder » Sun Feb 12, 2023 5:08 pm

I think i solved the problem.
After your last message i checked some of the tests i did and realized they were calling the wrong function.
In my code (i pasted here only a bit of it) i was putting the registers 2 and 3 of the XL9555 to zero by default, which in terms of output means "turned off"; So when i sat the BIT3 of register 6 as an output, i turned the usb off by default (that pin was for enabling USB power).
Before that, i was having some code operating with the register 2 and with other things, setting the bit3 as zero (i did a blink test to see if everything was ok even if the USB was not working properly).

However, thank you for your help and patience, your questions made me find the error! 8-) 8-)

ESP_Sprite
Posts: 8884
Joined: Thu Nov 26, 2015 4:08 am

Re: Strange microUSB behaviour with ESP32-S3 I2C and XL9555 (lib v5.0)

Postby ESP_Sprite » Sun Feb 12, 2023 11:56 pm

Good to hear you managed to solve it :)

Who is online

Users browsing this forum: Arun12 and 66 guests