I2C Interrupt

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

Re: I2C Interrupt

Postby MicroController » Mon Dec 11, 2023 12:49 pm

zeynep01 wrote:
Mon Dec 11, 2023 6:38 am
I don't use FreeRTOS I use bare-metal. I want to use I2C Interrupt. What can I do?
Can you clarify what you mean by 'bare-metal'?
Why do you want to not 'use FreeRTOS'?

All the IDF drivers make use of FreeRTOS functionality internally. If you don't want that, you can't use the IDF drivers.

zeynep01
Posts: 9
Joined: Fri Jul 07, 2023 9:41 am

Re: I2C Interrupt

Postby zeynep01 » Tue Dec 12, 2023 8:35 am

MicroController wrote:
Mon Dec 11, 2023 12:49 pm
zeynep01 wrote:
Mon Dec 11, 2023 6:38 am
I don't use FreeRTOS I use bare-metal. I want to use I2C Interrupt. What can I do?
Can you clarify what you mean by 'bare-metal'?
Why do you want to not 'use FreeRTOS'?

All the IDF drivers make use of FreeRTOS functionality internally. If you don't want that, you can't use the IDF drivers.
I hope my explanation is clearer this time. I intend to implement my core algorithm utilizing a state-machine bare-metal approach. Does the ESP-IDF leverage the I2C function via Interrupt Service Routines (ISRs)? Consequently, it seems superfluous to employ explicit interrupt functions.

Jeroen88
Posts: 4
Joined: Sun Feb 17, 2019 10:13 am

Re: I2C Interrupt

Postby Jeroen88 » Wed Dec 27, 2023 1:40 pm

I wanted to do something similar but I understand that using an ISR is impossible. @microcontroller, any ideas how to do this using a task? If I use the Arduino IDE, at what priority should the task run? And is there any possibility to make it asynchronous? If I look at esp32-hal-i2c.c I see that:

Code: Select all

i2cWrite(num, txAddress, txBuffer, txLength, _timeOutMillis);
and

Code: Select all

i2cRead(num, address, rxBuffer, size, _timeOutMillis, &rxLength);
both take a timeout parameter, so I see no way to e.g. introduce a vTaskDelay and release control to other tasks?

In more general terms my question is: what is a good way to read I2C devices while blocking the MCU at a minimum? What I want to do is to read four ADC's (Texas Instruments ADS1015) at 3.3 kHz, which is quite challenging I think? I run the I2C bus at a clock frequency of 1 MHz.

Thanks for your help!

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

Re: I2C Interrupt

Postby MicroController » Thu Dec 28, 2023 3:04 pm

If I use the Arduino IDE, at what priority should the task run? And is there any possibility to make it asynchronous?
The priority doesn't really matter much here, unless you have other tasks hogging the CPU that need to be preempted when an I2C transaction is finished.
Asynchronous... well, depends on the definition, see below.
both take a timeout parameter, so I see no way to e.g. introduce a vTaskDelay and release control to other tasks?
Not sure about Arduino, but the 'bare' ESP-IDF drivers will yield the CPU while waiting for a transaction to finish; most likely the Arduino wrappers do the same, so no problem there.
The IDF drivers don't support an 'asynchronous' programming style, which mostly is a good thing. Still, the I2C hardware will run concurrently to the CPU, and the CPU will run other tasks while one is blocked waiting for I2C to finish.
What I want to do is to read four ADC's (Texas Instruments ADS1015) at 3.3 kHz, which is quite challenging I think?
See also here :)
For best speed, I suggest making the conversions 'overlapping', i.e. start ADC1, start ADC2, start ADC3, start ADC4, read ADC1, read ADC2, read ADC3, read ADC4. This way, the ADCs are working in parallel while the MCU is communicating with the other ADCs.

(Reviewing the older post, I found it'd take 86 I2C clocks per sample. At 1MHz, that's 86us, or 344us of just bus time for 4 ADCs. This would limit you to ~2.9kHz max. on a single I2C bus.)

Who is online

Users browsing this forum: No registered users and 72 guests