ESP32 read i2c or i3c in IRQ macro

Post here to discuss any new features, components, chips, etc, that you would like to see in Flowcode.
stefan.erni
Valued Contributor
Posts: 997
http://meble-kuchenne.info.pl
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 190 times
Been thanked: 217 times

Re: ESP32 read i2c or i3c in IRQ macro

Post 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?

mnfisher
Valued Contributor
Posts: 1453
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 135 times
Been thanked: 707 times

Re: ESP32 read i2c or i3c in IRQ macro

Post 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

mnfisher
Valued Contributor
Posts: 1453
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 135 times
Been thanked: 707 times

Re: ESP32 read i2c or i3c in IRQ macro

Post 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
LabNation_Screenshot12.png (199.5 KiB) Viewed 514 times
Martin
Attachments
lsdm3_int.fcfx
(24.74 KiB) Downloaded 7 times

mnfisher
Valued Contributor
Posts: 1453
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 135 times
Been thanked: 707 times

Re: ESP32 read i2c or i3c in IRQ macro

Post 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.

stefan.erni
Valued Contributor
Posts: 997
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 190 times
Been thanked: 217 times

Re: ESP32 read i2c or i3c in IRQ macro

Post 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
2025-04-23_08-22-08.PNG (66.99 KiB) Viewed 481 times

stefan.erni
Valued Contributor
Posts: 997
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 190 times
Been thanked: 217 times

Re: ESP32 read i2c or i3c in IRQ macro

Post by stefan.erni »

I found the component and I copie the component

I working now

Code: Select all

%ProgramData%\MatrixTSL\FlowcodeV10\Components
Attachments
Notify.fcpx
(1.69 KiB) Downloaded 6 times

mnfisher
Valued Contributor
Posts: 1453
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 135 times
Been thanked: 707 times

Re: ESP32 read i2c or i3c in IRQ macro

Post 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

stefan.erni
Valued Contributor
Posts: 997
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 190 times
Been thanked: 217 times

Re: ESP32 read i2c or i3c in IRQ macro

Post 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
2025-04-23_16-12-47.PNG (7.71 KiB) Viewed 244 times

mnfisher
Valued Contributor
Posts: 1453
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 135 times
Been thanked: 707 times

Re: ESP32 read i2c or i3c in IRQ macro

Post 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

stefan.erni
Valued Contributor
Posts: 997
Joined: Wed Dec 02, 2020 10:53 am
Has thanked: 190 times
Been thanked: 217 times

Re: ESP32 read i2c or i3c in IRQ macro

Post 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.
Uart_int.fcfx
(24.55 KiB) Downloaded 3 times
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
2025-04-24_11-13-19.PNG (71.29 KiB) Viewed 56 times
Pinned to task:
2025-04-23_11-09-56.PNG
2025-04-23_11-09-56.PNG (231.87 KiB) Viewed 56 times

Post Reply