Datasheet

Table Of Contents
Ê9 ; The Instr mechanism allows stop/start/repstart sequences to be programmed
10 ; by the processor, and then carried out by the state machine at defined points
11 ; in the datastream.
12 ;
13 ; The "Final" field should be set for the final byte in a transfer.
14 ; This tells the state machine to ignore a NAK: if this field is not
15 ; set, then any NAK will cause the state machine to halt and interrupt.
16 ;
17 ; Autopull should be enabled, with a threshold of 16.
18 ; Autopush should be enabled, with a threshold of 8.
19 ; The TX FIFO should be accessed with halfword writes, to ensure
20 ; the data is immediately available in the OSR.
21 ;
22 ; Pin mapping:
23 ; - Input pin 0 is SDA, 1 is SCL (if clock stretching used)
24 ; - Jump pin is SDA
25 ; - Side-set pin 0 is SCL
26 ; - Set pin 0 is SDA
27 ; - OUT pin 0 is SDA
28 ;
29 ; The OE outputs should be inverted in the system IO controls!
30 ; (It's possible for the inversion to be done in this program,
31 ; but costs 2 instructions: 1 for inversion, and one to cope
32 ; with the side effect of the MOV on TX shift counter.)
33
34 .program i2c
35 .side_set 1 opt
36
37 do_nack:
38 ; Check if NAK was expected; if so, continue
39 jmp y-- entry_point
40 ; Stop and ask processor to come help us :(
41 irq wait 0 rel
42
43 do_byte:
44 set x, 7
45 bitloop:
46 out pindirs, 1 [7]
47 nop side 1 [2] ; SCL rising edge
48 wait 1 pin, 1 [4] ; Allow clock to be stretched
49 in pins, 1 [7]
50 jmp x-- bitloop side 0 [7] ; SCL falling edge
51
52 ; Handle ACK pulse
53 out pindirs, 1 [7]
54 nop side 1 [7] ; SCL rising edge
55 wait 1 pin, 1 [7] ; Allow clock to be stretched
56 jmp pin do_nack side 0 [2]
57
58 .extern entry_point
59 .wrap_target
60 out x, 6
61 out y, 1
62 jmp !x do_byte
63 out null, 32
64 do_exec:
65 out exec, 16
66 jmp x-- do_exec
67 .wrap
RP2040 Datasheet
3.7. Outdated Examples 365