micropython rp2040 PIO interrupt not firing

586 Views Asked by At

This code works but the interrupt only triggers when running on statemachine 0:

Although it is working I want to know if there are other ways to solve it

from machine import Pin, PWM 
from time import sleep
import rp2

class PioLoader():
    
    @rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)
    def blink():
        wrap_target()
        set(pins, 1)   [31]
        nop()          [31]
        nop()          [31]
        nop()          [31]
        nop()          [31]
        set(pins, 0)   [31]
        nop()          [31]
        nop()          [31]
        nop()          [31]
        nop()          [31]
        irq(0)
        wrap()


    def irqHandler(sm):
        self.sm.active(0)
        print("Finished") 
     
    def __init__(self): 
        pass

    def test(self):
        sm = rp2.StateMachine(0, self.blink, freq=2000, set_base=Pin(25))
        sm.irq(self.irqHandler)
        print(sm)
        sm.active(1)
        sleep(2) 
        sm.active(0)    

Can anyone help figuring the issue out?

1

There are 1 best solutions below

0
On

Found that statemachines 0 to 3 work with irq(0 to 3) and machines 4-7 need irq(0 to 3)

The solution is to use irq(rel(0)) which works in all cases. Phew!!!! Hope this helps someone else.