I was trying to add a second external interrupt to my code. I thought it might help me get out of the while loop.
So tried to duplicate the way the first external interupt worked
So i added
And i had to comment the machine.disable_irq() and enable machine.enable_irq(state) or i had this terrible message when i triggered the interupt.
Code: Select all
interrupt_counter = 0
total_interrupts_counter = 0
reset_counter_val = 0
def inter_counter(pin):
global interrupt_counter
interrupt_counter = interrupt_counter+1
def reset_counter(pin):
global reset_counter_val
reset_counter_val = reset_counter_val + 1
def update_led(i):
zeros = 16 - i
print(zeros)
for e in range(zeros):
clock.value(0)
data.value(0)
clock.value(1)
clock.value(0)
for e in range(i):
clock.value(0)
data.value(1)
clock.value(1)
clock.value(0)
latch.value(0)
latch.value(1)
latch.value(0)
print('did the leds')
msg = json.dumps({"client_id": CLIENT_ID, "led": i, "event": event})
sleep(0.1)
print(msg)
client.publish(TOPIC, msg)
reed.irq(trigger=Pin.IRQ_RISING, handler=inter_counter)
counter_reset.irq(trigger=Pin.IRQ_FALLING, handler=reset_counter)
while True:
if interrupt_counter > 0:
sleep(0.1)
state = machine.disable_irq()
interrupt_counter = 0
machine.enable_irq(state)
total_interrupts_counter = total_interrupts_counter+1
print("Interrupt has occurred: " + str(total_interrupts_counter))
update_led(total_interrupts_counter % 17)
if reset_counter_val > 1:
print("reset has occurred: " + str(reset_counter_val))
sleep(0.1)
state = machine.disable_irq()
interrupt_counter = 0
total_interrupts_counter = 0
reset_counter_val = 0
update_led(0)
machine.enable_irq(state)
Code: Select all
Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1)
Core 1 register dump:
PC : 0x40092960 PS : 0x00060734 A0 : 0x80091ba2 A1 : 0x3ffc12f0
A2 : 0x3ffe86ac A3 : 0x3ffba7c0 A4 : 0x00000cbd A5 : 0x3f420737
A6 : 0x0000abab A7 : 0x00000000 A8 : 0x3ffba7c0 A9 : 0x00000018
A10 : 0x3ffba7c0 A11 : 0x00000018 A12 : 0x00000000 A13 : 0x00000001
A14 : 0x0000abab A15 : 0x000001ae SAR : 0x00000001 EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff
Backtrace: 0x40092960:0x3ffc12f0 0x40091b9f:0x3ffc1310 0x40090a6f:0x3ffc1330 0x4011d0b9:0x3ffc1370 0x4010b5e9:0x3ffc1390 0x4011d721:0x3ffc13c0 0x4011dc4d:0x3ffc13e0 0x4010cf48:0x3ffc1420 0x4010d56e:0x3ffc1450 0x4010d676:0x3ffc1470 0x400f2729:0x3ffc1490 0x40189a41:0x3ffc14b0 0x400e6064:0x3ffc14e0 0x400e60ce:0x3ffc1510 0x400dfd6e:0x3ffc1540 0x400dbf71:0x3ffc1570 0x400dbfd9:0x3ffc1590 0x400e91ff:0x3ffc15b0 0x400dfdf0:0x3ffc1650 0x400dbf71:0x3ffc1680 0x400dbfd9:0x3ffc16a0 0x400e91ff:0x3ffc16c0 0x400dfdf0:0x3ffc1760 0x400dbf71:0x3ffc17e0 0x400e9175:0x3ffc1800 0x400dfdf0:0x3ffc18a0 0x400dbf71:0x3ffc1920 0x400dbf9e:0x3ffc1940 0x400f756a:0x3ffc1960 0x400f77cd:0x3ffc1a00 0x400f782b:0x3ffc1a20 0x400effc5:0x3ffc1a40 0x40090179:0x3ffc1a70
Core 0 register dump:
PC : 0x400911a8 PS : 0x00060034 A0 : 0x800918aa A1 : 0x3ffb0920
A2 : 0x3ffb0f9c A3 : 0x00060a23 A4 : 0x8009129c A5 : 0x3ffb0920
A6 : 0x00000003 A7 : 0x00060023 A8 : 0x0000abab A9 : 0xb33fffff
A10 : 0x0000abab A11 : 0x00060021 A12 : 0x00000001 A13 : 0x00000001
A14 : 0x0000cdcd A15 : 0x00060023 SAR : 0x0000001d EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000
Backtrace: 0x400911a8:0x3ffb0920 0x400918a7:0x3ffb0940 0x40090247:0x3ffb0960 0x40090069:0x3ffb0980 0x400846e6:0x3ffb0990 0x4018a4ff:0x00000000
Rebooting.
After some research i noticed the guilty line was the MQTT call at the end of my update_led function... so i swapped the two last lines.
Code: Select all
machine.enable_irq(state)
update_led(0)
Probably best not to mess with these.