modelI2cEchoDevice

Test I2C peripheral: reads back to the master what it has just written to it

Extends from Internal.Devices.PartialI2cDevice (Base of the I2C slave peripherals: open-drain electrical link, bus decoding, behaviour described by a Python script).

Information

The test component of the I2C bus, counterpart of UartEchoDevice. Its script (Resources/Scripts/Device/i2c_echo.py) remembers the bytes of the last write phase and sends them back unchanged when the master reads — several times in a row if the master asks for more.

It is used to validate a complete chain before connecting the final peripheral: multi-byte frames, register read behind a repeated START (readfrom_mem), several peripherals at different addresses on the same bus (change addresses), and operation with or without pull-up resistors (usePullUp).

valueOut: number of write phases received, total number of bytes received, first byte of the last write (-1 as long as nothing has been received).

Parameters

TypeNameDefaultDescription
Electrical › Supply
BooleanuseSupplyPin (from PartialSupplyPin)falseShow the VCC supply pin: the peripheral is supplied by the circuit (its high levels follow VCC, its consumption IQ is drawn from VCC) - unchecked: ideal internal supply VOH, nothing to wire
Modelica.Units.SI.VoltageVOH (from PartialSupplyPin)Interfaces.VOHLogic high voltage: ideal internal supply, high level of the outputs and of the pull-ups - with the VCC pin, the voltage of VCC is used instead
Modelica.Units.SI.CurrentIQ (from PartialSupplyPin)1e-3Current drawn from VCC by the peripheral (quiescent consumption, outputs excluded)
BooleanuseGroundPin (from PartialSupplyPin)trueShow the GND pin - unchecked: the peripheral is referenced to the simulation ground (0 V), nothing to wire
I2C bus
Stringaddresses (from PartialI2cDevice)"0x42"7-bit address(es) the peripheral answers to, e.g. "0x42" or "0x3E, 0x62" (at most 4)
BooleanusePullUp (from PartialI2cDevice)falseCarry the pull-up resistors of SDA and SCL to the supply (at least one component of the bus must do it)
Modelica.Units.SI.ResistanceRPullUp (from PartialI2cDevice)4700Pull-up resistance of each line
Behaviour
StringscriptPath (from PartialI2cDevice)""Script .py describing the behaviour (on_write / on_read / outputs / lines)
Inputs / outputs › Inputs (handler argument v)
BooleanuseValueInput (from PartialI2cDevice)falseTake the quantities from the valueIn connector rather than from a constant
IntegernIn (from PartialI2cDevice)1Number of quantities received from the model
RealfixedValue (from PartialI2cDevice)0Value used when valueIn is not connected
Inputs / outputs › Outputs (return value of outputs())
IntegernOut (from PartialI2cDevice)1Number of quantities returned to the model by outputs() - leave the connector unconnected if unused
Electrical › Levels
Modelica.Units.SI.VoltageVIH (from PartialI2cDevice)Interfaces.VIHThreshold above which an input reads high
Modelica.Units.SI.VoltageVIL (from PartialI2cDevice)Interfaces.VILThreshold below which an input reads low
Electrical › Impedances
Modelica.Units.SI.ResistanceROut (from PartialI2cDevice)Interfaces.ROutResistance of the SDA output transistor when it pulls the line to ground
Modelica.Units.SI.ConductanceGOff (from PartialI2cDevice)1e-9Leakage of the SDA output transistor when off (line released)
Modelica.Units.SI.CapacitanceCIn (from PartialI2cDevice)10e-12Input capacitance of each pin (SDA, SCL)
Modelica.Units.SI.ResistanceRIn (from PartialI2cDevice)10Series resistance of each pin (pad), between the bus wire and the input capacitance

Connectors

TypeNameDefaultDescription
Modelica.Electrical.Analog.Interfaces.NegativePinGND (from PartialSupplyPin)Common reference (ground), to be connected to the microcontroller's one - shown when useGroundPin is checked
Modelica.Electrical.Analog.Interfaces.PositivePinVCC (from PartialSupplyPin)Supply of the peripheral (e.g. 3V3(OUT) of a Raspberry Pi Pico) - shown when useSupplyPin is checked
Modelica.Electrical.Analog.Interfaces.PositivePinSDA (from PartialI2cDevice)I2C bus data - to be connected to the SDA pin of the microcontroller and of the other peripherals
Modelica.Electrical.Analog.Interfaces.PositivePinSCL (from PartialI2cDevice)I2C bus clock - to be connected to the SCL pin of the microcontroller and of the other peripherals
Modelica.Blocks.Interfaces.RealInput[nIn]valueIn (from PartialI2cDevice)Quantities supplied by the model, passed to the script's handlers (argument v)
Modelica.Blocks.Interfaces.RealOutput[nOut]valueOut (from PartialI2cDevice)Quantities returned by outputs() - the peripheral then becomes an actuator

Components

TypeNameDefaultDescription
BooleansdaDriveLow (from PartialI2cDevice)The peripheral pulls SDA to ground (acknowledge, or 0 bit read by the master)
Booleanbusy (from PartialI2cDevice)A phase addressed to this peripheral is in progress
IntegereventSeq (from PartialI2cDevice)Incremented at each completed write or read phase
StringlastEvent (from PartialI2cDevice)Summary of the last completed phase (log)
Stringline1 (from PartialI2cDevice)First line of text returned by lines() (displays)
Stringline2 (from PartialI2cDevice)Second line of text returned by lines()