i2c_master_cmd_begin Timeout Error lasting 1000 ticks, despite much shorter timeout setting

squirtle321
Posts: 11
Joined: Tue Jan 11, 2022 9:26 pm

i2c_master_cmd_begin Timeout Error lasting 1000 ticks, despite much shorter timeout setting

Postby squirtle321 » Mon Oct 17, 2022 1:56 pm

Hi there,

I've got a block of code which is occasionally blocking one of my tasks for a full second, leading to horrible jitter. Upon further investigation it seems like i2c_master_cmd_begin(...) is blocking for a full second. I have the parameter ticks_to_wait set to be much lower, which according to documentation should set the maximum ticks to wait before issuing a timeout. The issue is intermittent, but leads to instability in my firmware.

Here is the code:

Code: Select all

    i2c_cmd_handle_t cmd = i2c_cmd_link_create();
    i2c_master_start(cmd);
    i2c_master_write_byte(cmd, AS5600_ADDRESS << 1 | I2C_MASTER_WRITE, 0x1);
    i2c_master_write_byte(cmd, REGISTER_0, ACK_CHECK_EN);

    i2c_master_start(cmd);
    i2c_master_write_byte(cmd, (AS5600_ADDRESS << 1) | READ_BIT, ACK_CHECK_EN);
    i2c_master_read(cmd, (uint8_t*) &s.half_word, 2, I2C_MASTER_LAST_NACK);
    i2c_master_stop(cmd);

    TickType_t pre_ticks = xTaskGetTickCount();

    esp_err_t ret = i2c_master_cmd_begin(i2c_port, cmd, 2);

    if (ret != ESP_OK)
    {
        ESP_LOGE(TAG, "READ FAILED, TICKS = %d, ERROR CODE = %s", xTaskGetTickCount() - pre_ticks, esp_err_to_name(ret));
    }

    i2c_cmd_link_delete(cmd);
Logs:
READ FAILED, TICKS = 1000, ERROR CODE = ESP_ERR_TIMEOUT

Anyone seen this issue before?

Thanks

eliott
Posts: 18
Joined: Sat Mar 28, 2020 11:57 am

Re: i2c_master_cmd_begin Timeout Error lasting 1000 ticks, despite much shorter timeout setting

Postby eliott » Mon Oct 17, 2022 8:39 pm

Hello,

I have a the same problem and I think it's related to master write at first.

My signal shows that the master I2C doesn't transmit the 9th bit for slave ACK. My slave send an ACK but the master timout after the eighth bit. You can see on the attached image that my slave maintain ACK.

Then after 1 second wait the master send the databit.

My code was working at first EPS8266, now I'm on ESP32-WROOM-E (on ESP32-Ethernet Starter kit)

I updated today IDF from 4.2 to 4.4.2 last release, same problem.

I check with the documentation everything seems to be okay.

Same problem if I use ACK_IGNORE.

Code: Select all

#define I2C_WRITE 0
#define I2C_READ 1

#define ACK 0
#define NACK 1

#define ACK_VERIFY 1
#define ACK_IGNORE 0

Code: Select all

esp_err_t MASTER_I2C_WRITE(uint8_t adress, uint8_t * p_data, uint8_t lenth, uint8_t close_action)
{
	while(flag_busy);
	flag_busy=1;
	
	if(i2c_handle == NULL)
	{
		i2c_handle=i2c_cmd_link_create();
	}

	i2c_master_start(i2c_handle);	
	i2c_master_write_byte(i2c_handle,(adress | I2C_WRITE), ACK_IGNORE);		
	i2c_master_write(i2c_handle, p_data, lenth, ACK_IGNORE);
	
	if(close_action==STOP) 
	{	
		i2c_master_stop(i2c_handle);
		i2c_error=i2c_master_cmd_begin(I2C_NUM_0, i2c_handle, (1 / portTICK_PERIOD_MS));	
		i2c_cmd_link_delete(i2c_handle);
		flag_busy=0;
		i2c_handle=NULL;
				
		if(i2c_error != ESP_OK) 
		{
			ESP_LOGE(TAG, "Write STOP: %s",esp_err_to_name(i2c_error));
			return ESP_FAIL;
		}
	}

	return ESP_OK;
}
Thank you for help.
Attachments
image_2022-10-17_224048903.png
image_2022-10-17_224048903.png (26.54 KiB) Viewed 2031 times
i2cmasterbits.JPG
i2cmasterbits.JPG (57.76 KiB) Viewed 2031 times
long timeout.JPG
long timeout.JPG (154.41 KiB) Viewed 2031 times

eliott
Posts: 18
Joined: Sat Mar 28, 2020 11:57 am

Re: i2c_master_cmd_begin Timeout Error lasting 1000 ticks, despite much shorter timeout setting

Postby eliott » Mon Oct 17, 2022 9:35 pm

At my side the problem has been solved by enable interrupts: ESP_INTR_FLAG_INTRDISABLED is not OK

This works:

Code: Select all

i2c_error=i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER,0,0,ESP_INTR_FLAG_LOWMED);

Who is online

Users browsing this forum: MicroController and 217 guests