modelEcho
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
| Type | Name | Default | Description |
|---|---|---|---|
| MCU | mcu | scriptPath = Resources/Scripts/MCU/i2c_echo.py | |
| MicroPythonMCU.Peripherals.I2cEchoDevice | echo | Echo at address 0x42, carrying the pull-up resistors of the bus | |
| 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 |