ESP32 IDF extend I2C buffer size

avgustine13
Posts: 4
Joined: Mon Nov 26, 2018 3:40 pm

ESP32 IDF extend I2C buffer size

Postby avgustine13 » Mon Nov 26, 2018 3:48 pm

Hi to everyone.
I have such a problem.
As I understand the I2C buffer (master mode) in ESP32 is limited to 32 bytes.
I need to increase it for more big amounts of data (up to 64 bytes or even 128).

How can I implement this?

Kind regards.
Ivan.

Xiong Yu
Posts: 9
Joined: Wed Apr 11, 2018 12:08 am

Re: ESP32 IDF extend I2C buffer size

Postby Xiong Yu » Tue Nov 27, 2018 11:38 am

https://docs.espressif.com/projects/esp ... _t6size_tb

Try using this function. It uses a linked list to achieve longer data

avgustine13
Posts: 4
Joined: Mon Nov 26, 2018 3:40 pm

Re: ESP32 IDF extend I2C buffer size

Postby avgustine13 » Tue Nov 27, 2018 11:51 am

I'm using this functions.
i2c_master_read_byte, i2c_master_read
I'm reading a sensor, get info that 60 bytes available but read only 32.

ESP_houwenxiang
Posts: 118
Joined: Tue Jun 26, 2018 3:09 am

Re: ESP32 IDF extend I2C buffer size

Postby ESP_houwenxiang » Wed Nov 28, 2018 3:18 am

Hi
32 bytes is hardware limit, but you can read more than 32 bytes each time by software. can you provide your read function?
wookooho

avgustine13
Posts: 4
Joined: Mon Nov 26, 2018 3:40 pm

Re: ESP32 IDF extend I2C buffer size

Postby avgustine13 » Wed Nov 28, 2018 8:00 am

esp_err_t i2c_master_read_byte(i2c_cmd_handle_t cmd_handle, uint8_t* data, i2c_ack_type_t ack)
{
I2C_CHECK((data != NULL), I2C_ADDR_ERROR_STR, ESP_ERR_INVALID_ARG);
I2C_CHECK(cmd_handle != NULL, I2C_CMD_LINK_INIT_ERR_STR, ESP_ERR_INVALID_ARG);
I2C_CHECK(ack < I2C_MASTER_ACK_MAX, I2C_ACK_TYPE_ERR_STR, ESP_ERR_INVALID_ARG);

i2c_cmd_t cmd;
cmd.ack_en = 0;
cmd.ack_exp = 0;
cmd.ack_val = ((ack == I2C_MASTER_LAST_NACK) ? I2C_MASTER_NACK : (ack & 0x1));
cmd.byte_num = 1;
cmd.op_code = I2C_CMD_READ;
cmd.data = data;
return i2c_cmd_link_append(cmd_handle, &cmd);
}

esp_err_t i2c_master_read(i2c_cmd_handle_t cmd_handle, uint8_t* data, size_t data_len, i2c_ack_type_t ack)
{
I2C_CHECK((data != NULL), I2C_ADDR_ERROR_STR, ESP_ERR_INVALID_ARG);
I2C_CHECK(cmd_handle != NULL, I2C_CMD_LINK_INIT_ERR_STR, ESP_ERR_INVALID_ARG);
I2C_CHECK(ack < I2C_MASTER_ACK_MAX, I2C_ACK_TYPE_ERR_STR, ESP_ERR_INVALID_ARG);
I2C_CHECK(data_len > 0, I2C_DATA_LEN_ERR_STR, ESP_ERR_INVALID_ARG);

if(ack != I2C_MASTER_LAST_NACK) {
return i2c_master_read_static(cmd_handle, data, data_len, ack);
} else {
if(data_len == 1) {
return i2c_master_read_byte(cmd_handle, data, I2C_MASTER_NACK);
} else {
esp_err_t ret;
if((ret = i2c_master_read_static(cmd_handle, data, data_len - 1, I2C_MASTER_ACK)) != ESP_OK) {
return ret;
}
return i2c_master_read_byte(cmd_handle, data + data_len - 1, I2C_MASTER_NACK);
}
}
}

avgustine13
Posts: 4
Joined: Mon Nov 26, 2018 3:40 pm

Re: ESP32 IDF extend I2C buffer size

Postby avgustine13 » Wed Nov 28, 2018 8:06 am

And here is the whole source file
Attachments
i2c.c
(55.67 KiB) Downloaded 1077 times

ESP_houwenxiang
Posts: 118
Joined: Tue Jun 26, 2018 3:09 am

Re: ESP32 IDF extend I2C buffer size

Postby ESP_houwenxiang » Wed Dec 05, 2018 6:42 am

avgustine13 wrote:
Wed Nov 28, 2018 8:06 am
And here is the whole source file
Hi, avgustine13

Why you don't use the i2c dirver in IDF?
wookooho

Who is online

Users browsing this forum: No registered users and 313 guests