I'd like to confirm the behaviour of i2c on esp32-s3

klajsd2
Posts: 1
Joined: Sat Feb 03, 2024 3:29 pm

I'd like to confirm the behaviour of i2c on esp32-s3

Postby klajsd2 » Sat Feb 03, 2024 3:38 pm

Hi,
I have 2 ESP devices communicating together with i2c.
The master is a ESP32
Slave is a esp32-s3 with address 0x28

The master periodically issues a read to get 4 bytes from the slave. When there is no data in the queue of the slave (the s3), I get the following:

Code: Select all

START, 51h, ACK, 51h, ACK, FFh, ACK, FFh, ACK, FFh, NACK, STOP
51h would be (28h << 1) | 1. So that makes sense.

But why does the slave respond back with

Code: Select all

51h,FFh,FFh,FFh
?
I would expect either:
-

Code: Select all

START, 51h, NACK

- Or

Code: Select all

START, 51h, ACK, FFh, ACK, FFh, ACK, FFh, ACK, FFh, NACK, STOP
Is the behaviour I am seeing normal? Is this expected or does this mean I either have an issue in my code or with the wiring. Or maybe it's an issue with the S3?


FWIW, this is the code I'm using on the master:

Code: Select all

    i2c_cmd_handle_t cmd = i2c_cmd_link_create();
    i2c_master_start(cmd);
    i2c_master_write_byte(cmd, (0x28 << 1) | 1, ACK_CHECK_EN);
    i2c_master_read_byte(cmd, data_rd, (i2c_ack_type_t)ACK_VAL);
    i2c_master_read_byte(cmd, data_rd + 1, (i2c_ack_type_t)ACK_VAL);
    i2c_master_read_byte(cmd, data_rd + 2, (i2c_ack_type_t)ACK_VAL);
    i2c_master_read_byte(cmd, data_rd + 3, (i2c_ack_type_t)I2C_MASTER_LAST_NACK);
    i2c_master_stop(cmd);
    esp_err_t ret = i2c_master_cmd_begin(i2c_num, cmd, 10);
    i2c_cmd_link_delete(cmd);

MicroController
Posts: 1553
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: I'd like to confirm the behaviour of i2c on esp32-s3

Postby MicroController » Sun Feb 04, 2024 8:21 pm

Haven't used I2C slave mode yet, but my understanding is that you must provide the data before the master tries to read it. Failure to do so should result in an interrupt from the slave's I2C controller when the master tries to read from the empty FIFO. However, I don't see that the IDF driver would provide an API way to handle that interrupt, so I guess that the slave just sends out 'garbage' when there's no actual data available.
If my assumption is correct, the procedure for an I2C slave would be that the slave's application keeps data in the FIFO current at all times to be ready for an 'unsolicited' read from the master at any time.

Who is online

Users browsing this forum: No registered users and 61 guests