0

Extract of longer program. Just to toggle the .side pin and then quit the PIO program. Causes loop and have to nuke the PICO! Loops before the 'Run' print. Thanks

TypeError: function takes 2 positional arguments but 1 were given

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

def main():
    sm = rp2.StateMachine(0, test, freq=180000, sideset_base=Pin(8
    sm.irq(irqHandler)                 
    sm.active(1)                         
    print('Run')
    sleep(5)
    print('Slept')

def irqHandler(self, sm):
    print('IRQ servo')
 
@rp2.asm_pio(sideset_init=rp2.PIO.OUT_LOW)    
def test():
    mov(x,x)        .side(1)
    mov(x,x)        .side(0)       
    irq(block, 0)
2
  • Are you sure that print is re-entrant on a PICO? You have to be very careful what you do inside an ISR because you have no way of knowing what the processor was in the middle of doing. Why not toggle an LED on/off in the ISR to show that it is being reached? Commented Oct 27 at 17:23
  • Thanks, you are correct. The print was just there for debugging. Commented Oct 27 at 17:25

1 Answer 1

0

The 'self' in def irqHandler(self, sm): was a hangover from the full program where it was a class.

Needed sm.active(0) in the handler to stop the PIO running

Needed wrap_target() at the end of the program to keep it in a loop until stopped. Otherwise it just reran and piled up the interrupts.

Learn something every day!!!!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.