Skip to content

Commit 38958d4

Browse files
committed
tests/multi_extmod/machine_i2c_target.py: Add I2CTarget multi test.
Signed-off-by: Damien George <[email protected]>
1 parent b8d32cf commit 38958d4

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Test I2CTarget, using hardware I2C controller
2+
#
3+
# Requires:
4+
# - instance0 to be a PYBx, with I2C connections to the Y I2C ports
5+
# - instance1 to be a RPI_PICOx with I2C connections to pins 9/8
6+
7+
import time
8+
from machine import I2C, I2CTarget
9+
import machine
10+
11+
ADDR = 67
12+
13+
14+
# I2C controller
15+
def instance0():
16+
i2c = machine.I2C("Y")
17+
18+
multitest.next()
19+
multitest.wait("target stage 1")
20+
21+
i2c.writeto_mem(ADDR, 0, "abcdefgh")
22+
multitest.broadcast("controller stage 2")
23+
multitest.wait("target stage 3")
24+
print(i2c.readfrom_mem(ADDR, 0, 8))
25+
multitest.broadcast("controller stage 4")
26+
27+
28+
def irq(i2c_target):
29+
print(i2c_target.irq().flags())
30+
time.sleep_us(100)
31+
32+
33+
# I2C target
34+
def instance1():
35+
buf = bytearray(8)
36+
i2c_target = machine.I2CTarget(0, ADDR, scl=9, sda=8, mem=buf)
37+
i2c_target.irq(irq, I2CTarget.IRQ_ADDR_MATCH, hard=True)
38+
39+
multitest.next()
40+
multitest.broadcast("target stage 1")
41+
multitest.wait("controller stage 2")
42+
print(buf)
43+
multitest.broadcast("target stage 3")
44+
multitest.wait("controller stage 4")
45+
print('done')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#

0 commit comments

Comments
 (0)