Possible to add interrupt to scl pin i2c?

av_jui
Posts: 8
Joined: Wed Jan 08, 2025 11:09 am

Possible to add interrupt to scl pin i2c?

Postby av_jui » Wed Jan 08, 2025 11:36 am

hallo

is it possible to add an interrupt function to the scl pin. i have tried different things that won´t work.

the first thing i have tried
- setup gpio and interrupt after read out basic things from i2c slave
- after i get an interrupt i disable the gpio and interrupt and reactivate the i2c master.
- try to read out date from slave.
- reactivate gpio and interrupt.

it seems not working, because the slave get back to factory settings after reactivation.

the second thing i have tried is to activate the interrupt on scl pin without gpio.
- setup interrupt on scl pin
- after i get an interrupt i disable interrupt.
- try to read out date from slave.
- reactivate interrupt.

Code: Select all

gpio_set_intr_type((gpio_num_t)SDA_PIN, GPIO_INTR_ANYEDGE);
gpio_intr_enable((gpio_num_t)SDA_PIN);
....
no interrupt was handled.

at the moment i used idf 5.1/5.2 and the legacy driver on esp32-s3.

Code: Select all

    i2c_conf = {
        .mode = I2C_MODE_MASTER,
        .sda_io_num = SDA_PIN,
        .scl_io_num = SLC_PIN,
        .sda_pullup_en = GPIO_PULLUP_ENABLE,
        .scl_pullup_en = GPIO_PULLUP_ENABLE,
        .master = {
            .clk_speed = I2C_MASTER_FREQ_HZ,
        },
        //.clk_flags = 0,
    };
    
     i2c_param_config(I2C_NUM_0, &i2c_conf);

     err = i2c_driver_install(I2C_NUM_0, i2c_conf.mode, 0, 0, 0);
  
i had also a look into the gpio matrix function but i don´t get this work. maybe someone could help me with this.

thanks
rene
Visit my github account :arrow: https://github.com/avjui

User avatar
ok-home
Posts: 157
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

Re: Possible to add interrupt to scl pin i2c?

Postby ok-home » Wed Jan 08, 2025 1:23 pm

After initialization of the i2c driver pin SCL is set to OUT mode, and the signal does not reach the gpio registers,
try AFTER initialization of the i2c driver, connect gpio to the input
PIN_INPUT_ENABLE(GPIO_PIN_MUX_MUX_REG[SCL]) ;
simultaneous operation of the interrupt on gpio and any of the interfaces on the same gpio is possible.

av_jui
Posts: 8
Joined: Wed Jan 08, 2025 11:09 am

Re: Possible to add interrupt to scl pin i2c?

Postby av_jui » Wed Jan 08, 2025 3:01 pm

hey.

but when i have a look to the

Code: Select all

i2c_set_pin()
function, which will used by setting up, it will be declared as 'IN/OUT'pin.
https://github.com/espressif/esp-idf/bl ... i2c.c#L951.
so i don´t need to write to register any more?

thanks
rene
Visit my github account :arrow: https://github.com/avjui

User avatar
ok-home
Posts: 157
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

Re: Possible to add interrupt to scl pin i2c?

Postby ok-home » Thu Jan 09, 2025 1:24 am

so i don´t need to write to register any more?
Yes, in this case you don't need to install anything additional, just process incoming interrupts.
but I don't really understand why you do it ?
The driver itself will read the data from SDA and give it to you when all data is received (i2c_slave_read_buffer in the old driver, or callback in the new one)
You are trying to handle interrupts at 100kHz ( 400kHz ), this is generally not very good from the GPIO interrupt controller point of view, it simply may not be able to handle interrupts of 5 microseconds, much less 1.25 microseconds ( AnyAge ).

av_jui
Posts: 8
Joined: Wed Jan 08, 2025 11:09 am

Re: Possible to add interrupt to scl pin i2c?

Postby av_jui » Thu Jan 09, 2025 10:45 am

thank you for replay

but only install the isr seems not to work. see first post.

background of this condition can you see in the datasheet section 5.5 of the tlv493d sensor.
in the master controlled mode you have the ability to enable interrupt. the tlv493d save the data to register and after that it will pull down scl to signal ready for read. this is the fasted way to read out. the polling mode i have already integrated.
You are trying to handle interrupts at 100kHz ( 400kHz ), this is generally not very good from the GPIO interrupt controller point of view, it simply may not be able to handle interrupts of 5 microseconds, much less 1.25 microseconds ( AnyAge ).
maybe this is the problem.

any ideas what other test i can make?

thank rene
Visit my github account :arrow: https://github.com/avjui

User avatar
ok-home
Posts: 157
Joined: Sun May 02, 2021 7:23 pm
Location: Russia Novosibirsk
Contact:

Re: Possible to add interrupt to scl pin i2c?

Postby ok-home » Thu Jan 09, 2025 1:41 pm

very strange
now I checked (this code is from another application)

Code: Select all

    
    gpio_install_isr_service(0);                 // default
    gpio_set_intr_type(pin_trigger, trigger_edge);
    gpio_isr_handler_add(pin_trigger, la_ll_trigger_isr, (void *)pin_trigger);
    gpio_intr_disable(pin_trigger);
    gpio_intr_enable(pin_trigger); // start transfer on irq

Code: Select all

void IRAM_ATTR la_ll_trigger_isr(void *pin)
{
    gpio_matrix_in(0x38, CAM_V_SYNC_IDX, false); // enable cam
    gpio_intr_disable((int)pin);
}
this code starts before i2c initialization (standard initialization),
no additional actions on gpio initialization are needed,
interrupt is triggered by scl, starts logic analyzer (on the same esp32s3).
scl-gpio2, sda=gpio3,pin_trigger=gpio2
i2c.JPG
i2c.JPG (69.66 KiB) Viewed 1015 times

Who is online

Users browsing this forum: Baidu [Spider] and 6 guests