modelMultiDevice

Three I2C peripherals on the same bus: the microcontroller finds them with scan() and talks to each one without crosstalk

Extends from Modelica.Icons.Example (Icon for runnable examples).

Information

Three I2cEchoDevice share the same two wires SDA/SCL, at addresses 0x10, 0x11 and 0x12. The program (Scripts/MCU/i2c_multi.py, at 400 kHz):

  1. finds the three peripherals with scan() — one probe per possible address, only the three present ones acknowledge;
  2. writes a frame of a different length to each one, then reads them back one by one: each returns only what was written to it, the other two stay silent (no crosstalk);
  3. addresses 0x20, where nobody answers: OSError(EIO).

GP7 goes high if everything is as expected.

Two peripherals carry pull-up resistors (usePullUp = true), the third does not: the two pairs end up in parallel, as when several off-the-shelf modules are connected to the same bus. The bus works as soon as there is at least one — the verification scenario verify_23 (Resources/Verification/NoPullUp.mo) covers the case where there is none.

Components

TypeNameDefaultDescription
MCUmcuscriptPath = Resources/Scripts/MCU/i2c_multi.py
MicroPythonMCU.Peripherals.I2cEchoDevicee1Echo at address 0x10 - carries a pair of pull-up resistors
MicroPythonMCU.Peripherals.I2cEchoDevicee2Echo at address 0x11 - also carries a pair of pull-ups, in parallel with that of e1
MicroPythonMCU.Peripherals.I2cEchoDevicee3Echo at address 0x12 - no pull-ups
Modelica.Electrical.Analog.Basic.Groundground
Modelica.Electrical.Analog.Basic.Resistorr7limits the current of led7 (GP7)
MicroPythonMCU.Peripherals.LEDled7GP7: lights up if the three I2C exchanges are as expected