GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing docs.micropython.org — Programmable IO — MicroPython latest documentation This is the documentation for the latest development branch of MicroPython and may refer to features that are not available in released versions. If you are looking for the documentation for a specific release, use the drop-down menu on the left and select the desired version. Programmable IOThe RP2xxx family of microcontrollers provides hardware support for standard communication protocols like I2C, SPI and UART. For protocols where there is no hardware support, or where there is a requirement of custom I/O behaviour, Programmable Input Output (PIO) comes into play. Also, some MicroPython applications make use of a technique called bit banging in which pins are rapidly turned on and off to transmit data. This can make the entire process slow as the processor concentrates on bit banging rather than executing other logic. However, PIO allows bit banging to happen in the background while the CPU is executing the main work. PIO State MachinesState machines transfer data to/from other entities using First-In-First-Out (FIFO) buffers, which allow the state machine and main processor to work independently yet also synchronise their data. The FIFOs can be linked to the DMA to transfer larger amounts of data without extensive CPU usage. RP2040The RP2040 has two PIO blocks, each with four independent state machines (total of 8). Each FIFO has four words (each of 32 bits) per state machine (TX and RX). RP2350The RP2350 has three PIO blocks, each with four independent state machines (total of 12). Similar to the RP2040, each state machine has a four-word FIFO per state machine (TX and RX), but they have some additional functions For each state machine:
CompatibilityRP2350 PIO is backward-compatible with RP2040, with some additional enhancements. At the moment, native support for RP2350 PIO enhancements is very limited, but work for some features are already in progress InstructionsEach PIO block has 32 instructions of memory shared among its four state machines. All PIO instructions follow a common pattern: <instruction> .side(<side_set_value>) [<delay_value>] The side-set There are nine instructions which perform the following tasks:
The instruction modifiers are:
There are also directives:
An exampleTake the # Example using PIO to blink an LED and raise an IRQ at 1Hz. import time from machine import Pin import rp2 @rp2.asm_pio(set_init=rp2.PIO.OUT_LOW) def blink_1hz(): # Cycles: 1 + 1 + 6 + 32 * (30 + 1) = 1000 irq(rel(0)) set(pins, 1) set(x, 31) [5] label("delay_high") nop() [29] jmp(x_dec, "delay_high") # Cycles: 1 + 1 + 6 + 32 * (30 + 1) = 1000 nop() set(pins, 0) set(x, 31) [5] label("delay_low") nop() [29] jmp(x_dec, "delay_low") # Create the StateMachine with the blink_1hz program, outputting on Pin(25). sm = rp2.StateMachine(0, blink_1hz, freq=2000, set_base=Pin(25)) # Set the IRQ handler to print the millisecond timestamp. sm.irq(lambda p: print(time.ticks_ms())) # Start the StateMachine. sm.active(1) This creates an instance of class The
The entire routine takes exactly 2000 cycles of the state machine. Setting the frequency of the state machine to 2000Hz makes the LED blink at 1Hz. This example works identically on both RP2040 and RP2350 (using StateMachine ID 0). On
RP2350, higher Compatibility NotesPIO programs using the basic instructions shown here are fully compatible between RP2040
and RP2350. The MicroPython RP2350 offers additional advanced features (new instructions, FIFO modes, security, GPIO relocation) not covered in this introduction; see the RP2350 datasheet for details. Some programs may require minor adjustments due to differences in default GPIO reset states between the two chips.
Versions and Downloads
latest
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |