Datasheet

Table Of Contents
10 #include "hardware/pio.h"
11 #include "differential_manchester.pio.h"
12
13 // Differential serial transmit/receive example
14 // Need to connect a wire from GPIO2 -> GPIO3
15
16 const uint pin_tx = 2;
17 const uint pin_rx = 3;
18
19 int main() {
20 setup_default_uart();
21
22 PIO pio = pio0;
23 uint sm_tx = 0;
24 uint sm_rx = 1;
25
26 uint offset_tx = pio_add_program(pio, &differential_manchester_tx_program);
27 uint offset_rx = pio_add_program(pio, &differential_manchester_rx_program);
28 printf("Transmit program loaded at %d\n", offset_tx);
29 printf("Receive program loaded at %d\n", offset_rx);
30
31 // Configure state machines, set bit rate at 5 Mbps
32 differential_manchester_tx_program_init(pio, sm_tx, offset_tx, pin_tx, 125.f / (16 *
Ê 5));
33 differential_manchester_rx_program_init(pio, sm_rx, offset_rx, pin_rx, 125.f / (16 *
Ê 5));
34
35 pio_sm_enable(pio, sm_tx, false);
36 pio_sm_put_blocking(pio, sm_tx, 0);
37 pio_sm_put_blocking(pio, sm_tx, 0x0ff0a55a);
38 pio_sm_put_blocking(pio, sm_tx, 0x12345678);
39 pio_sm_enable(pio, sm_tx, true);
40
41 for (int i = 0; i < 3; ++i)
42 printf("%08x\n", pio_sm_get_blocking(pio, sm_rx));
43 }
3.6.7. Addition
Although not designed for computation, PIO is quite likely Turing-complete, and it is conjectured that it could run DOOM,
given a sufficiently high clock speed.
Pico Examples: https://github.com/raspberrypi/pico-examples/tree/pre_release/pio/addition/addition.pio Lines 1 - 19
Ê1 .program addition
Ê2
Ê3 ; Pop two 32 bit integers from the TX FIFO, add them together, and push the
Ê4 ; result to the TX FIFO. Autopush/pull should be disabled as we're using
Ê5 ; explicit push and pull instructions.
Ê6 ;
Ê7 ; This program uses the two's complement identity x + y == ~(~x - y)
Ê8
Ê9 pull
10 mov x, ~osr
11 pull
12 mov y, osr
13 jmp test ; this loop is equivalent to the following C code:
14 incr: ; while (y--)
15 jmp x-- test ; x--;
16 test: ; This has the effect of subtracting y from x, eventually.
RP2040 Datasheet
3.6. Examples 360