Skip to the content.

E31 — RP ↔ CH32 I2C link (RP I2C1 master, CH32 I2C2 slave)

   
ID E31
Date 2026-12-04
Status done: 100 k / 400 k / 1 MHz exact, 0 errors with a STOP before each read (94 / 89 kB/s at 1 MHz); up to 3 MHz requested still clean (230 / 203 kB/s), reads fail at 4 MHz; with a repeated start the slave sometimes loses the register byte (1464–1656 bad bytes per 640 KB)
Decisions D114 (DECISIONS.md)
Board #1 (rev A); RP GPIO2/3 (I2C1) ↔ CH32 PB10/PB11 (I2C2, AF4), 4.7 kΩ pull-ups on +3V3_CH; CH32 ×32 (I2C clocked from HCLK 96 MHz, FREQ = 48)
Firmware + results fw/tests/2026-12-04-1-links, raw: i2c.txt
Scripts links_i2c.py; CH32 i2cs on [variant]\|off\|stat; RP i2ct <khz> <n> [seed] [stop]

Summary: The CH32 answers as an interrupt-driven slave at 0x42 with a 256-byte register file. The RP writes [reg 0, 64 bytes], then writes [reg 0] and reads 64 bytes back, and compares. With a repeated start between the register write and the read, about 2 chunks in 64 KB come back from the wrong address: the slave never saw the register byte, so the read starts where the previous write ended (pointer 64). A STOP between the two gives 0 errors at every speed up to 3 MHz requested.

Results

Speed sweep, STOP before each read:

requested actual (RP) bytes write kB/s read kB/s bad
100 kHz 100 000 2 KB 10.2 10.0 0
400 kHz 400 000 16 KB 39.8 38.5 0
1 MHz 1 000 000 64 KB 94.1 88.9 0
1.5 MHz 1 500 000 64 KB 135.1 122.2 0
2 MHz 2 000 000 64 KB 172.6 155.6 0
3 MHz 3 000 000 64 KB 230.3 203.4 0
4 MHz 3 947 368 1 KB 275.4 — read errors (16)

Above 1 MHz the bus is outside the I2C Fast-mode Plus spec; the “actual” rates are the RP’s divider setting, and the throughput shows the real bus is slower (the CH32 stretches the clock while its ISR runs). Use 1 MHz.

Soak, 1 MHz, 10 × 64 KB per case:

slave ISR variant repeated start STOP before read
0 (STAR2 read on every event) 1464 bad bytes (20+ chunks) 0
1 (STAR2 read only on ADDR) 1656 bad bytes (22+ chunks) 0

Slave counters (variant 0): ADDR 61 440 (= exactly one per transaction), badptr 23 = reads that started with the pointer at 64, not 0.

Lesson

Put a diagnostic counter in the ISR that records the state at the moment the error shows (here the pointer at the first byte of a read) before changing the ISR. Check the counters against the expected totals before building a theory on top of them.

Chip facts and numbers: fw/LEARNINGS.md. All experiments: index.