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.
ESP32 IDF extend I2C buffer size
Re: ESP32 IDF extend I2C buffer size
https://docs.espressif.com/projects/esp ... _t6size_tb
Try using this function. It uses a linked list to achieve longer data
Try using this function. It uses a linked list to achieve longer data
-
- Posts: 4
- Joined: Mon Nov 26, 2018 3:40 pm
Re: ESP32 IDF extend I2C buffer size
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.
i2c_master_read_byte, i2c_master_read
I'm reading a sensor, get info that 60 bytes available but read only 32.
-
- Posts: 118
- Joined: Tue Jun 26, 2018 3:09 am
Re: ESP32 IDF extend I2C buffer size
Hi
32 bytes is hardware limit, but you can read more than 32 bytes each time by software. can you provide your read function?
32 bytes is hardware limit, but you can read more than 32 bytes each time by software. can you provide your read function?
wookooho
-
- Posts: 4
- Joined: Mon Nov 26, 2018 3:40 pm
Re: ESP32 IDF extend I2C buffer size
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);
}
}
}
{
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);
}
}
}
-
- Posts: 4
- Joined: Mon Nov 26, 2018 3:40 pm
Re: ESP32 IDF extend I2C buffer size
And here is the whole source file
- Attachments
-
- i2c.c
- (55.67 KiB) Downloaded 1080 times
-
- Posts: 118
- Joined: Tue Jun 26, 2018 3:09 am
Re: ESP32 IDF extend I2C buffer size
Hi, avgustine13
Why you don't use the i2c dirver in IDF?
wookooho
Who is online
Users browsing this forum: MSN [Bot] and 177 guests