Trouble ESP32 and ISM330DHCX using interrupts

Hi,

I am trying to work with the ESP32 and the ISM330DHCX, using the set_event_interrupt method. But I’m seeing a weird behaviour.

If I enable the interrupts on the ESP32 when the INT1 signal of ISM330DHCX comes, then I cannot read from the accelerometer.

But if I don’t use the ESP32 interrupt, and poll the input pin in the loop instead then all works ok.

Here is my code:

import streams

from stm.ism330dhcx import ism330dhcx

streams.serial()

rd = 0

def int_came():
global rd
print("INT1 received!")
rd = 1

# Setup D21 as input - This is connected to INT1 of the accelerometer
pinMode(D21, INPUT)
# Setup interrupt trigger on rising edge
onPinRise(D21, int_came, debounce=200)

# Setup sensor 
print("start...")
accgyro = ism330dhcx.ISM330DHCX(SPI1, D22)
print("Ready!")
print("--------------------------------------------------------")

sleep(100)
accgyro.set_event_interrupt(1, "acc", True)

while True:
    print(".")
    if rd:
        print("came here #1")
        acc = accgyro.get_acc_data()
        str = "Acc: %.2f," %acc[0]
        str = str + " %.2f," %acc[1]
        str = str + " %.2f," %acc[2]
        print(str)
        print("came here #2")
        rd = 0
    sleep(500)

Here also the output:

ets Jun  8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:3648
ho 0 tail 12 room 4
load:0x40078000,len:9928
ho 0 tail 12 room 4
load:0x40080400,len:5788
entry 0x400806c0
E (33) boot: OTA: -1/-1  -1/-1  -1/-4
E (33) boot: Invalid ota, returning default vm 0
E (33) boot: Starting vm 0
start...
Ready!
--------------------------------------------------------
.
INT1 received!
.
came here #1

Hi @niag, thanks for reaching out.

I’ve tried your code on a different board and it seems like it is working correctly.

I would suggest you 3 solutions to try (in order):

  1. Try the example of the library without the interrupt. You can find the example in the “example” section of Zerynth Studio. If this is working then we can exclude that there is a problem with SPI1;
  2. If [1] is not working then you could try using SPI0, if that’s possible;
  3. We are working on fixing an esp32 bug which cause the interrupts handler to be called only when both onPinRise an onPinFall are registerd. You could try registering an empty function on the onPinFall and test again.

Let me know how it goes,
L.M.

1 Like

Hi @Syrinxos,

many thanks for the rapid reply :slight_smile:

I actually have already tried out the library without the interrupt (sorry, I should have said that already) and it worked without problems.

So I jumped directly to your proposed solution 3 and voila! It did actually work as expected.
I therefore suppose this can also be attributed to the bug you mentioned.

Thank you again.

BR,
NA

Good to know you solved the issue!

We will release the fix as soon as we solve it, thanks for your understanding.

Best.
L.M.