Page 2 of 3
Re: ESP32 read i2c or i3c in IRQ macro
Posted: Tue Apr 22, 2025 11:07 am
by stefan.erni
Hi Martin
'semaphore' or 'signal' or 'Flag' i have already tried, it works, but the watchdog is causing problems.
sometimes I don't need a delay sometimes I need 10mSec delay.
is there any other way than using a delay'? for example a watchdog reset?
or a setting that only triggers after seconds?
Re: ESP32 read i2c or i3c in IRQ macro
Posted: Tue Apr 22, 2025 11:29 am
by mnfisher
A task using a semaphore shouldn't cause a wdt error - needs to wait on receipt of a message from the interrupt handler - unless it is getting called too quickly and never actually waiting on a signal? (It doesn't need a delay though) Can you post / PM the code you tried?
Resetting the wdt used to work (I posted feedthedog somewhere on the board) - but it doesn't work in later versions.. It is probably not a good idea - things will stop working (BT, WiFi, tasks etc)
I've wondered if it would be possible to have a WDT ISR - but again probably not sensible.
It is also possible to extend the period (see menuconfig) - but it just delays the problem
Martin
Re: ESP32 read i2c or i3c in IRQ macro
Posted: Tue Apr 22, 2025 10:34 pm
by mnfisher
I tried a timer interrupt driven version.
Again I increased the stack size to 32768 and added target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-pointer-sign) to CMakeLists.txt
Reading 6 bytes of the accelerometer takes about 214uS. So I set the timer to read a sample every 625uS and set the accelerometer to 1.6kHz. I used the notify component I posted at
viewtopic.php?t=2548&hilit=esp32+task - however, as the interrupt needs to use a line of C to send the notification I would probably either add the SendFromISR to the component - or just wait for the notification using a line of C...
If the other components (gyro / temp) can be read by using a contiguous read of 12 or 14 bytes - then it should be able to give the same rate.
Here - I read the accelerometer data (6 bytes) to an array of 1000 6 byte entries - the code would need to mark when full before going on to the second buffer...
With this rate - I get no issues with the WDT..... Checking the time between successive samples - I get 625uS too

I also tested 500uS - 2kHz - and again the esp32 is stable with no wdt errors.

- LabNation_Screenshot12.png (199.5 KiB) Viewed 515 times
Martin
Re: ESP32 read i2c or i3c in IRQ macro
Posted: Tue Apr 22, 2025 10:44 pm
by mnfisher
I also discovered that you can drag and drop a folder to the forum... If that folder is an esp32 project folder this is very much a mistake ! The majority of the files are rejected (phew) - leaving (just) a few for deletion.
Re: ESP32 read i2c or i3c in IRQ macro
Posted: Wed Apr 23, 2025 7:31 am
by stefan.erni
it looks like this will soon working fine.
I just suspect I need a component Notify ?
Component:

- 2025-04-23_08-22-08.PNG (66.99 KiB) Viewed 482 times
Re: ESP32 read i2c or i3c in IRQ macro
Posted: Wed Apr 23, 2025 7:41 am
by stefan.erni
I found the component and I copie the component
I working now
Code: Select all
%ProgramData%\MatrixTSL\FlowcodeV10\Components
Re: ESP32 read i2c or i3c in IRQ macro
Posted: Wed Apr 23, 2025 9:40 am
by mnfisher
Can possibly push a bit faster - using esp_i2c_write_then_read (name from memory) - reduced the delay in the reads.
Some thoughts on double buffering....
Assuming a buffer size of 1000 records - increase the receive buffer to 2000 records (note this might be adjusted to suit the 'save' task - maybe 1 SD card sector size?)
Then the read sends a notification to Save when pos == 1000 (save buffer_ 0 - buffer[0..999]) and pos == 0 (save buffer 1 [1000..1999) - the notification can wake the save task and also pass the buffer number to save?
Alternatively - using two buffers - requires a conditional in the read - but again notify the save task on 'full'...
Martin
Re: ESP32 read i2c or i3c in IRQ macro
Posted: Wed Apr 23, 2025 3:21 pm
by stefan.erni
Hi Martin
I did what you suggested and it works with 960Hz and 2 pieces of LSM6dsv16bx with ACC and Gyro (I am still testing)
(But I had to switch off Bluetooth)
Many thanks Martin.
buffer size of 1000 records
Alternatively - using two buffers - requires a conditional in the read - but again notify the save task on 'full'...
Buffer Size for 1000 records 2x ACC xyz Gyro xyz in =12000

- 2025-04-23_16-12-47.PNG (7.71 KiB) Viewed 245 times
Re: ESP32 read i2c or i3c in IRQ macro
Posted: Wed Apr 23, 2025 3:41 pm
by mnfisher
That's good

Have the 'whiskers' disappeared from the trace?
Also can you save the data fast enough?
The Bluetooth might be struggling for processor time - the co-operative multi-tasking isn't given much time here..
Martin
Re: ESP32 read i2c or i3c in IRQ macro
Posted: Thu Apr 24, 2025 10:43 am
by stefan.erni
Yes the 'whiskers' disappeared from the trace
Yes for this project it's fast enough.
We are on the right track.
I suspect that we will soon have a good IRQ for the ESP32.
I have used the pinned task to write data to the disk. The 10ms I need for the watchdog reset is no problem.
But I can't use it to sample data. I tried using the Notify component but that doesn't work either with my task.
With you task it's perfect!
I have not yet understood the Notify component exactly.
I have changed your program to test the IRQ and the uart shows text or ad error message.
There is already commanda to reset the wdt but I don't know how to use.
https://docs.espressif.com/projects/esp ... /wdts.html
error from the wdt send to uart automatically

- 2025-04-24_11-13-19.PNG (71.29 KiB) Viewed 57 times
Pinned to task:

- 2025-04-23_11-09-56.PNG (231.87 KiB) Viewed 57 times