I2C slave interrupt entering for every address in the system

vazquezfran
Posts: 5
Joined: Thu Jun 06, 2024 1:41 pm

I2C slave interrupt entering for every address in the system

Postby vazquezfran » Tue Oct 08, 2024 1:16 pm

Hello,
I am working with a DevKit "esp32-c6-devkitc-1_v1.2". In my test set-up I have an I2C bus such as:
- Master --> different MCU than an ESP32
- Slave with address 0x41 --> different MCU than an ESP32
- Slave with address 0x42 --> ESP32 C6 devkit

I am using the configuration described in the "docs.espressif" page:
https://docs.espressif.com/projects/esp ... s/i2c.html

The I2C bus is working fine and the ESp32 is only acting for the 0x42 address. However, I am finding that the I2C interrupt ("i2c_slave_rx_done_callback") in the ESP32 is entering for both slave addresses (0x41, 0x42).

Is this expected?
If NOT, how to enter only for the proper address?
If YES, how is it possible to filter by address received inside the interrupt?

Thanks in advance for the help!

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

Re: I2C slave interrupt entering for every address in the system

Postby MicroController » Tue Oct 08, 2024 2:50 pm

I am using the configuration described in the "docs.espressif" page:
https://docs.espressif.com/projects/esp ... s/i2c.html
Please show the code you use to set up the I2C slave.

vazquezfran
Posts: 5
Joined: Thu Jun 06, 2024 1:41 pm

Re: I2C slave interrupt entering for every address in the system

Postby vazquezfran » Wed Oct 09, 2024 8:22 am

Code: Select all

const i2c_slave_config_t i2c_slv_config = {
    .addr_bit_len = I2C_ADDR_BIT_LEN_7,   // 7-bit address
    .clk_source = I2C_CLK_SRC_DEFAULT,    // set the clock source
    .i2c_port = 0,                        // set I2C port number
    .send_buf_depth = 256,                // set tx buffer length
    .scl_io_num = 7,                      // SCL gpio number
    .sda_io_num = 6,                      // SDA gpio number
    .slave_addr = 0x42,                   // slave address
};

void IIC_Config(void)
{
    //Init bus
    (void)i2c_new_slave_device(&i2c_slv_config, &i2c_slave_handle);
    
    i2c_receive_queue = xQueueCreate(1, sizeof(i2c_slave_rx_done_event_data_t));
    
    //Define "RX Done" callback
    i2c_slave_event_callbacks_t cbs = {
    .on_recv_done = IIC_Slave_Interrupt_RXDone_callback,
    };
    (void)i2c_slave_register_event_callbacks(i2c_slave_handle, &cbs, i2c_receive_queue);
}

void IIC_Write(const uint8_t* p_src, uint8_t ucNumBytes)
{
    (void)i2c_slave_transmit(i2c_slave_handle, p_src, ucNumBytes, 10000);
}

void IIC_Read(uint8_t* p_dest, uint8_t ucNumBytes)
{
    (void)i2c_slave_receive(i2c_slave_handle, p_dest, ucNumBytes);
}

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

Re: I2C slave interrupt entering for every address in the system

Postby MicroController » Wed Oct 09, 2024 9:35 am

Hmm.
It looks like the IDF I2C slave driver unconditionally executes the on_recv_done callback upon the I2C_TRANS_COMPLETE_INT, which, according to the TRM, is "Triggered when the I2C controller detects a STOP bit". The TRM doesn't mention any further conditions for this interrupt, so it may be that this interrupt triggers on every STOP seen on the bus even if the ESP is not actually addressed by the preceding transaction.
If this is the case, this may indicate that there's a bug in the IDF driver.

vazquezfran
Posts: 5
Joined: Thu Jun 06, 2024 1:41 pm

Re: I2C slave interrupt entering for every address in the system

Postby vazquezfran » Wed Oct 09, 2024 9:40 am

so it may be that this interrupt triggers on every STOP seen on the bus even if the ESP is not actually addressed by the preceding transaction
This is exactly the case because the interrupt enters for all the cases, reads, writes and for all the different addresses. Is it possible to get some support here about how to solve it?

Thanks!

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

Re: I2C slave interrupt entering for every address in the system

Postby MicroController » Wed Oct 09, 2024 2:21 pm

Maybe someone from Espressif will also chime in here with more information about the I2C_TRANS_COMPLETE_INT.

If my interpretation of the I2C_TRANS_COMPLETE_INT is correct, one could reasonably suspect a bug in the IDF driver, for which https://github.com/espressif/esp-idf/issues would be the place to report and get it fixed.

Who is online

Users browsing this forum: Baidu [Spider], nopnop2002 and 128 guests