MAX44009 two I2C reads without a stop in between
Posted: Sat Feb 06, 2021 4:45 pm
Hi all,
I have been trying to use MAX44009 light sensor, it stores the illumination data in two registers and the datasheet specifies that they need to be read one after another without generating a stop signal in between the two reads. Otherwise the two values may be out of sync.
I have not figured out a way how to set up the communication in ESP-IDF (on ESP32) so that no stop signal is sent between the two reads.
That is how the communication is supposed to be done: This is my code that does not work:
I have hooked up a logic analyzer and I can see that it does not clock the ACK or NAK after the first read and times out there:
The second read is never started. If I add a stop signal between the two reads, everything works, but there is a risk that the two values may be out of sync with each other.
Is it possible to do this type of communication on an ESP32?
I have been trying to use MAX44009 light sensor, it stores the illumination data in two registers and the datasheet specifies that they need to be read one after another without generating a stop signal in between the two reads. Otherwise the two values may be out of sync.
I have not figured out a way how to set up the communication in ESP-IDF (on ESP32) so that no stop signal is sent between the two reads.
That is how the communication is supposed to be done: This is my code that does not work:
Code: Select all
i2c_cmd_handle_t cmd1 = i2c_cmd_link_create();
i2c_master_start(cmd1);
i2c_master_write_byte(cmd1, (MAX44009_ADDRESS << 1) | I2C_MASTER_WRITE, ACK_CHECK_EN);
i2c_master_write_byte(cmd1, 0x03, ACK_CHECK_EN);
i2c_master_start(cmd1);
i2c_master_write_byte(cmd1, (MAX44009_ADDRESS << 1) | I2C_MASTER_READ, ACK_CHECK_EN);
i2c_master_read_byte(cmd1, register3, NACK_VAL);
//i2c_master_stop(cmd1); //if I uncomment this, the code works, but the two registers may not be synchronized
esp_err_t ret1 = i2c_master_cmd_begin(i2c_num, cmd1, 1000 / portTICK_PERIOD_MS);
i2c_cmd_link_delete(cmd1);
i2c_cmd_handle_t cmd2 = i2c_cmd_link_create();
i2c_master_start(cmd2);
i2c_master_write_byte(cmd2, (MAX44009_ADDRESS << 1) | I2C_MASTER_WRITE, ACK_CHECK_EN);
i2c_master_write_byte(cmd2, 0x04, ACK_CHECK_EN);
i2c_master_start(cmd2);
i2c_master_write_byte(cmd2, (MAX44009_ADDRESS << 1) | I2C_MASTER_READ, ACK_CHECK_EN);
i2c_master_read_byte(cmd2, register4, NACK_VAL);
i2c_master_stop(cmd2);
esp_err_t ret2 = i2c_master_cmd_begin(i2c_num, cmd2, 1000 / portTICK_PERIOD_MS);
i2c_cmd_link_delete(cmd2);
Is it possible to do this type of communication on an ESP32?