modelEcho

The microcontroller writes a multi-byte frame to an I2C peripheral, then reads it back

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

Information

First I2C dialogue: the microcontroller (master) writes the frame b'Hello I2C' (9 bytes) to the echo peripheral at address 0x42, reads it back, then reads a "register" behind a repeated START (readfrom_mem). GP7 goes high if the three exchanges are as expected, which the LED led7 shows.

The bus is electrical: plotting mcu.GP4.v (SCL) and mcu.GP5.v (SDA) shows the real sequence — START (SDA falls while SCL is high), 7-bit address + R/W bit, acknowledge from the slave (SDA pulled low on the 9th clock pulse), data bytes, STOP. echo.sdaDriveLow shows the instants when the slave, and not the master, holds SDA.

The pull-up resistors are carried by the echo (usePullUp = true). Disabling them keeps the lines low: the verification scenario verify_23 (Resources/Verification/NoPullUp.mo) covers this case.

Components

TypeNameDefaultDescription
MCUmcuscriptPath = Resources/Scripts/MCU/i2c_echo.py
MicroPythonMCU.Peripherals.I2cEchoDeviceechoEcho at address 0x42, carrying the pull-up resistors of the bus
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