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.
mnfisher
Valued Contributor
Posts: 1453
http://meble-kuchenne.info.pl
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 »

Hi Stefan,

You need the TaskId from xTaskCreatePinnedToCore - to pass to notify..

I think it is the last but one parameter - and you'll need to pass the address of a FC variable..

So if the variable is SaveToSDTask (needs to be a UINT32) - then pass &FCV_SAVETOSDTASK - the 'drag' variable to the C block is good here....
& - gets the address..

If you use Notify to wake the task then it shouldn'tneed a delay....

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

Yes I dont need a delay and there is no watchdog fired. Just change the command like this.

The cornumber needs to be on the end and the variable b4.
2025-04-24_14-09-47.PNG
2025-04-24_14-09-47.PNG (32.76 KiB) Viewed 155 times
working program:
Uart_int.fcfx
(25.02 KiB) Downloaded 5 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 »

For interest - I wanted to see if the accelerometer is returning 'meaningful' data....

I added a 'SaveData' macro - although in this case it outputs the first 4 6 value samples from the save buffer to UART... I went with using accel_data[0..499] as buffer 0 and [500.999] as buffer 1.
The ReadSample macro - notifies the SaveData macro when a buffer is full.

The values change more dramatically when I move the sensor - but I'm not much the wiser?

Martin
Attachments
lsdm3_int.fcfx
(27.54 KiB) Downloaded 11 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 »

Your IRQ handling is working fine. And reading faster I2C also!
I adjust for my hardware and let it run


If the sensor is flat on the table the z-axis has +16400 digit
2025-04-25_11-06-56.PNG
2025-04-25_11-06-56.PNG (6.06 KiB) Viewed 112 times
If I turn it 90 deg an other axis goes to -16300 and z-axis goes to zero
2025-04-25_11-09-19.PNG
2025-04-25_11-09-19.PNG (7.86 KiB) Viewed 112 times
so I turn 180 deg axis goes to goes to +16300
2025-04-25_11-11-23.PNG
2025-04-25_11-11-23.PNG (7.3 KiB) Viewed 112 times
mod program to send String to uart
lsdm3_int4.fcfx
(31.81 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 »

Thanks Stefan,

That's very helpful - I'll have a look and see if I can spot the pattern in my sensor's returns.

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 »

Just tested - and yes. The results look sensible...

Saving buffer 0 - (182,1678,-16281)
Saving buffer 1 - (154,652,-15675)
Saving buffer 0 - (-16348,436,500)
Saving buffer 1 - (-16326,482,950)
Saving buffer 0 - (-34,16344,-922)
Saving buffer 1 - (2,16330,-965)

With the board 'aligned' in each of the 3 planes. I set the delay between samples to 10ms - to allow a more sedate update rate...

Martin

Post Reply