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):
- finds the three peripherals with
scan()— one probe per possible address, only the three present ones acknowledge; - 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);
- 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
| Type | Name | Default | Description |
|---|---|---|---|
| MCU | mcu | scriptPath = Resources/Scripts/MCU/i2c_multi.py | |
| MicroPythonMCU.Peripherals.I2cEchoDevice | e1 | Echo at address 0x10 - carries a pair of pull-up resistors | |
| MicroPythonMCU.Peripherals.I2cEchoDevice | e2 | Echo at address 0x11 - also carries a pair of pull-ups, in parallel with that of e1 | |
| MicroPythonMCU.Peripherals.I2cEchoDevice | e3 | Echo at address 0x12 - no pull-ups | |
| Modelica.Electrical.Analog.Basic.Ground | ground | ||
| Modelica.Electrical.Analog.Basic.Resistor | r7 | limits the current of led7 (GP7) | |
| MicroPythonMCU.Peripherals.LED | led7 | GP7: lights up if the three I2C exchanges are as expected |