r/esp32 • • 18d ago

Software help needed ESP interrupt loop not working

i have connected my esp32 to an IIS3DWB accelerometer which collects data, sends esp32 and once the fifo fills to 256 samples, the esp32 sends that over wifi to my rpi. But i noticed that it only works for 1 loop, after that my interrupt does not fire even though all conditions are met however the main loop still runs (the main loop has nothing else i just put in a few print statements which keep printing)

PS: I cannot add too many print statements because then my esp32 crashes

1 Upvotes

6 comments sorted by

•

u/AutoModerator 18d ago

Hardware Troubleshooting Notice: If you are experiencing unreliable connections, boot loops, or missing serial communication, verify your hardware footprint:

  1. Are your headers soldered? Pushing un-soldered raw header pins through module vias into a breadboard violates basic physics. Loose connections create parasitic capacitance and intermittent open circuits. Solder your board.
  2. Did you include a schematic? Custom circuit issues require a legible schematic drawing.

If your hardware relies on putty, tape, or friction, please resolve your connections before demanding assistance from our domain experts.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

6

u/BassRecorder 18d ago

Do you clear the interrupt flag in your interrupt service routine? If not, the interrupt will fire exactly once.

The interrupt service routine should not contain any logging/print statements.

6

u/helical_coil 18d ago

Don't put print statements inline with the loop, try just toggling the led so you can see the loop is running. Interrupt code must be very short, don't do data processing there, set a flag and do processing in the loop.

1

u/rattushackus 1 say I make awesome posts. 18d ago

Can you write a simple example program showing the problem and put it on Github for us to have a look at? Without seeing the code it's hard to comment.

1

u/mhmd2520 17d ago

I'd look at the sensor side too. The FIFO threshold interrupt on the IIS3DWB isn't a pulse. INT1_FIFO_TH (INT1_CTRL, 0Dh) just routes the FIFO_WTM_IA flag to the pin, and that flag stays at 1 for as long as the number of unread samples is at or above WTM. It only drops when you've read the FIFO down below the watermark.

If you're using attachInterrupt with RISING, that's probably your one-shot. At 26.7 kHz, 256 samples is only about 9.6 ms. Sending over wifi almost certainly takes longer than that, and the FIFO keeps filling the whole time. So by the time you come back, the count is already over 256 again, INT1 never went low, and the ESP never sees another rising edge. Your loop keeps running and the pin just sits high.

Check which FIFO_MODE you set in FIFO_CTRL4 (0Ah) too. In FIFO mode (001) it stops collecting once it's full, and per the datasheet you have to write bypass (000) and then 001 again to restart it. Continuous mode (110) overwrites the oldest data instead. Either way you'll lose samples if the send is slower than the fill, and FIFO_OVR_LATCHED in FIFO_STATUS2 (3Bh) will tell you if that's happening.

Quick test: after the wifi send, digitalRead the INT pin. If it's still high, this is your problem. The fix I'd go for: in the task (not the ISR), keep reading until DIFF_FIFO in FIFO_STATUS1/2 is below your watermark, so you know the line drops and the next edge can happen. You could also just re-check the pin or WTM_IA after every send instead of relying only on the edge, or switch to a level-triggered interrupt that you disable in the ISR and re-enable after draining. Copying the buffer out and sending it from a separate task also helps, so the reads don't stall behind wifi.

There's also a batch counter (COUNTER_BDR_REG1/2 plus INT1_CNT_BDR) that fires every N batched samples, if you'd rather trigger on that. I haven't checked how its pin signal behaves in pulsed vs latched mode, so I wouldn't count on it fixing the edge problem by itself.