Datasheet

Table Of Contents
3.6.5. Manchester Serial TX and RX
Data Idle 0 0 1 1 0 1
Line
Figure 51. Manchester
serial line code. Each
data bit is represented
by either a high pulse
followed by a low
pulse (representing a
'0' bit) or a low pulse
followed by a high
pulse (a '1' bit).
Pico Examples: https://github.com/raspberrypi/pico-examples/tree/pre_release/pio/manchester_encoding/manchester_encoding.pio Lines 7 - 29
Ê7 .program manchester_tx
Ê8 .side_set 1 opt
Ê9
10 ; Transmit one bit every 12 cycles. a '0' is encoded as a high-low sequence
11 ; (each part lasting half a bit period, or 6 cycles) and a '1' is encoded as a
12 ; low-high sequence.
13 ;
14 ; Side-set bit 0 must be mapped to the GPIO used for TX.
15 ; Autopull must be enabled -- this program does not care about the threshold.
16 ; The program starts at the public label 'start'.
17
18 .wrap_target
19 do_1:
20 nop side 0 [5] ; Low for 6 cycles (5 delay, +1 for nop)
21 jmp get_bit side 1 [3] ; High for 4 cycles. 'get_bit' takes another 2 cycles
22 do_0:
23 nop side 1 [5] ; Output high for 6 cycles
24 nop side 0 [3] ; Output low for 4 cycles
25 public start:
26 get_bit:
27 out x, 1 ; Always shift out one bit from OSR to X, so we can
28 jmp !x do_0 ; branch on it. Autopull refills the OSR when empty.
29 .wrap
Starting from the label called start, this program shifts one data bit at a time into the X register, so that it can branch on
the value. Depending on the outcome, it uses side-set to drive either a 1-0 or 0-1 sequence onto the chosen GPIO. This
program uses autopull (Section 3.5.4.2) to automatically replenish the OSR from the TX FIFO once a certain amount of
data has been shifted out, without interrupting program control flow or timing. This feature is enabled by a helper function
in the .pio file which configures and starts the state machine:
Pico Examples: https://github.com/raspberrypi/pico-examples/tree/pre_release/pio/manchester_encoding/manchester_encoding.pio Lines 32 - 45
32 static inline void manchester_tx_program_init(PIO pio, uint sm, uint offset, uint pin, float
Ê div) {
33 pio_sm_set_pins_with_mask(pio, sm, 0, 1u << pin);
34 pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true);
35 pio_gpio_select(pio, pin);
36
37 pio_sm_config c = manchester_tx_program_get_default_config(offset);
38 sm_config_set_sideset_pins(&c, pin);
39 sm_config_set_out_shift(&c, true, true, 32);
40 sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
41 sm_config_set_clkdiv(&c, div);
42 pio_sm_init(pio, sm, offset + manchester_tx_offset_start, &c);
43
44 pio_sm_enable(pio, sm, true);
45 }
Another state machine can be programmed to recover the original data from the transmitted signal:
RP2040 Datasheet
3.6. Examples 355