I'm trying to create an event driven program on an ESP-WROOM-32 and interrupts are driving me mad.
There are 8 input pins generating interrupts when they go low plus at least one timer routine called every couple of ms. I first tried interrupts only, no timer. This works for three to five interrupts, then stops working. If I add a timer it becomes even worse. The timer service routine works until one of the interrupts comes in. Then it stops working, the interrupt is also not served, the whole thing becomes unresponsive.
Here's the code with unnecessary parts left out:
Code: [Local Link Removed for Guests]
'Ports
SENSOR1 = 36
SENSOR2 = 39
SENSOR3 = 34
SENSOR4 = 32
SENSOR5 = 33
SENSOR6 = 25
SENSOR7 = 35
SENSOR8 = 26
'...
'Sensor init
pin.mode SENSOR1, input
pin.mode SENSOR2, input
pin.mode SENSOR3, input
pin.mode SENSOR4, input
pin.mode SENSOR5, input
pin.mode SENSOR6, input
pin.mode SENSOR7, input
pin.mode SENSOR8, input
interrupt SENSOR1, irh1
interrupt SENSOR2, irh2
interrupt SENSOR3, irh3
interrupt SENSOR4, irh4
interrupt SENSOR5, irh5
interrupt SENSOR6, irh6
interrupt SENSOR7, irh7
interrupt SENSOR8, irh8
'...
timer0 2000, ti
wlog "before wait"
wait
wlog "past wait"
irh1:
if pin(SENSOR1) = 1 then return
interrupt SENSOR1, OFF
wlog "1"
return
irh2:
if pin(SENSOR2) = 1 then return
interrupt SENSOR2, OFF
wlog "2"
return
irh3:
if pin(SENSOR3) = 1 then return
interrupt SENSOR3, OFF
wlog "3"
return
irh4:
if pin(SENSOR4) = 1 then return
interrupt SENSOR4, OFF
wlog "4"
return
irh5:
if pin(SENSOR5) = 1 then return
interrupt SENSOR5, OFF
wlog "5"
return
irh6:
if pin(SENSOR6) = 1 then return
interrupt SENSOR6, OFF
wlog "6"
return
irh7:
if pin(SENSOR7) = 1 then return
interrupt SENSOR7, OFF
wlog "7"
return
irh8:
if pin(SENSOR8) = 1 then return
interrupt SENSOR8, OFF
wlog "8"
return
ti:
wlog "timer"
return
end
It should serve every input interrupt once printing its number to the console. Independently the timer should chime up every 2 secs.
But this is not what happens. Timer prints "timer" every 2 secs until I pull one of the inputs two ground. It simply stops working.
If I leave out the timer activation before wait, a few interrupts (between three and six regardless of sensor number) are handled correctly, then it also stops working.
My fault or is something wrong with interrupts?
Thanks for your help.
Cheers
Ulli