I2C Bus
The I2C bus interface allows you to decode traffic sent over the I2C SDA line. In order to decode the traffic, a number of parameters need to be set based on your knowledge how the I2C bus should be operating.
Creating an I2C Bus
To create an I2C bus, a scl (clock) net and sda (data) net need to be instantiated.
from lager import Net, NetType, I2C
sda = Net.get('I2C.SDA',
type=NetType.Logic,
setup_function=setup_nets,
teardown_function=teardown_nets)
scl = Net.get('I2C.SCL',
type=NetType.Logic,
setup_function=setup_nets,
teardown_function=teardown_nets)
i2c = I2C(scl=scl,sda=sda)
i2c.enable()
~ lager bus i2c --source-scl I2C.SCL --source-sda I2C.SDA --dut 1
Including RW Bit
When decoding I2C communication, it may be useful to either include the r/w bit in the address byte.
from lager import Net, NetType, I2C
sda = Net.get('I2C.SDA',
type=NetType.Logic,
setup_function=setup_nets,
teardown_function=teardown_nets)
scl = Net.get('I2C.SCL',
type=NetType.Logic,
setup_function=setup_nets,
teardown_function=teardown_nets)
i2c = I2C(scl=scl,sda=sda)
i2c.rw_on()
~ lager bus i2c --rw on --dut 1
Signal Threshold
This sets the assumed voltage threshold a rising or falling I2C signal should pass through.
from lager import Net, NetType, I2C
scl = Net.get('I2C.SCL',
type=NetType.Logic,
setup_function=setup_nets,
teardown_function=teardown_nets)
sda = Net.get('I2C.SDA',
type=NetType.Logic,
setup_function=setup_nets,
teardown_function=teardown_nets)
i2c = I2C(scl=scl,sda=sda)
i2c.set_signal_threshold(scl=1.5, sda=1.5)
~ lager bus i2c --level-scl 1.5 --level-sda 1.5 --dut 1