CANbus

Basic examples of CANbus communication.

Receive CAN bus message

import pyb
can = pyb.CAN( 1 )
can.setfilter( 0, pyb.CAN.LIST16, 0, (123, 124, 125, 126) )
print( can.recv(0) )

Send CAN bus message

import pyb
can = pyb.CAN( 1 )
can.setfilter( 0, pyb.CAN.LIST16, 0, (123, 124, 125, 126) )
can.send( b"message", 123 )

Send/Receive CAN bus message in loopback mode

import pyb
can = pyb.CAN( 1, pyb.CAN.LOOPBACK )
can.setfilter( 0, pyb.CAN.LIST16, 0, (123, 124, 125, 126) )
can.send( b"message", 123 )
print( can.recv(0) )