diff --git a/docs/rp2/quickref.rst b/docs/rp2/quickref.rst index 63b8928280..4824f390eb 100644 --- a/docs/rp2/quickref.rst +++ b/docs/rp2/quickref.rst @@ -92,6 +92,37 @@ Use the :ref:`machine.Pin ` class:: p4 = Pin(4, Pin.IN, Pin.PULL_UP) # enable internal pull-up resistor p5 = Pin(5, Pin.OUT, value=1) # set pin high on creation +Programmable IO (PIO) +--------------------- + +PIO is useful to build low-level IO interfaces from scratch. See the :mod:`rp2` module +for detailed explaination of the assembly instructions. + +Example using PIO to blink an LED at 1Hz:: + + from machine import Pin + import rp2 + + @rp2.asm_pio(set_init=rp2.PIO.OUT_LOW) + def blink_1hz(): + # Cycles: 1 + 7 + 32 * (30 + 1) = 1000 + set(pins, 1) + set(x, 31) [6] + label("delay_high") + nop() [29] + jmp(x_dec, "delay_high") + + # Cycles: 1 + 7 + 32 * (30 + 1) = 1000 + set(pins, 0) + set(x, 31) [6] + label("delay_low") + nop() [29] + jmp(x_dec, "delay_low") + + # Create and start a StateMachine with blink_1hz, outputting on Pin(25) + sm = rp2.StateMachine(0, blink_1hz, freq=2000, set_base=Pin(25)) + sm.active(1) + UART (serial bus) -----------------