CAN Bus

The CAN bus interface allows you to decode traffic sent over the CAN transceiver lines (tx/rx) or alternatively you can choose to decode the raw CAN differential lines. In order to decode the traffic, a number of parameters need to be set based on your knowledge how the CAN bus should be operating.

Creating a CAN Bus

To create a CAN bus, one of the following CAN nets needs to be instantiated: - TX - RX - CAN High (Physical CAN Signal) - CAN Low (Physical CAN Signal) - Differential (Physical CAN Signal measured with a differential probe)

create_can_bus.py
 from lager import Net, NetType, CAN

 tx = Net.get('CAN.TX',
         type=NetType.Logic,
         setup_function=setup_nets,
         teardown_function=teardown_nets)

 can = CAN(tx=tx)
 can.enable()
Create CAN Bus
~  lager bus can --source CAN.TX --dut 1

BAUD

This sets the assumed BAUD rate of the CAN bus being decoded.

set_can_baud.py
 from lager import Net, NetType, CAN

 tx = Net.get('CAN.TX',
         type=NetType.Logic,
         setup_function=setup_nets,
         teardown_function=teardown_nets)


 can = CAN(tx=tx)
 can.set_baud(50000)
Set CAN Bus BAUD
~  lager bus can --baud 500000 --dut 1

Signal Type

This sets the CAN bus signal that is being decoded.

set_can_signal_type.py
 from lager import Net, NetType, CAN

 tx = Net.get('CAN.TX',
         type=NetType.Logic,
         setup_function=setup_nets,
         teardown_function=teardown_nets)


 can = CAN(tx=tx)
 can.set_signal_type_tx()
Set CAN Bus Signal Type
~  lager bus can --signal-type tx --dut 1

Signal Threshold

This sets the assumed voltage threshold a rising or falling CAN signal should pass through.

set_can_threshold.py
 from lager import Net, NetType, CAN

 can = Net.get('CAN.TX',
         type=NetType.Logic,
         setup_function=setup_nets,
         teardown_function=teardown_nets)

 can = CAN(scl=scl,sda=sda)
 can.set_signal_threshold(1.5)
Set CAN Bus Threshold
~  lager bus can --level 1.5 --dut 1