Skip to content

MCP2515 class

class MCP2515

class MCP2515(dvr, cs, rst=None, clk=800000)

Creates an instance of the MCP2515 class. This class allows the control of MCP2515 devices.

Arguments:

  • drv – SPI Driver used ‘(SPI0, …)’
  • cs – Chip select of the SPI driver
  • rst – Reset pin (default None)
  • clk – Clock speed, default 800 kHz
MCP2515.init

init(idmode, speed, clock)

Initializes the MCP2515 chip

Arguments:

  • idmode – set the RX buffer id mode (selectable from mcp2515.MCP_STDEXT, mcp2515.MCP_STD, mcp2515.MCP_EXT, or mcp2515.MCP_ANY
  • speed – set the speed of the CAN communication
  • clock – set the clock of the CAN Communication

Possible combination of values for Clock and Speed are:

  • Clock –> 8MHZ
Clock Speed
“8MHZ” “5KBPS”
“8MHZ” “10KBPS”
“8MHZ” “20KBPS”
“8MHZ” “31KBPS”
“8MHZ” “33KBPS”
“8MHZ” “40KBPS”
“8MHZ” “50KBPS”
“8MHZ” “80KBPS”
“8MHZ” “100KBPS”
“8MHZ” “125KBPS”
“8MHZ” “200KBPS”
“8MHZ” “250KBPS”
“8MHZ” “500KBPS”
“8MHZ” “1000KBPS”
  • Clock –> 16MHZ
Clock Speed
“16MHZ” “5KBPS”
“16MHZ” “10KBPS”
“16MHZ” “20KBPS”
“16MHZ” “33KBPS”
“16MHZ” “40KBPS”
“16MHZ” “50KBPS”
“16MHZ” “80KBPS”
“16MHZ” “100KBPS”
“16MHZ” “125KBPS”
“16MHZ” “200KBPS”
“16MHZ” “250KBPS”
“16MHZ” “500KBPS”
“16MHZ” “1000KBPS”
  • Clock –> 20MHZ
Clock Speed
“20MHZ” “40KBPS”
“20MHZ” “50KBPS”
“20MHZ” “80KBPS”
“20MHZ” “100KBPS”
“20MHZ” “125KBPS”
“20MHZ” “200KBPS”
“20MHZ” “250KBPS”
“20MHZ” “500KBPS”
“20MHZ” “1000KBPS”
MCP2515.set_mode

set_mode(mode)

Sets the operation mode of the MCP2515.

Arguments: mode – operation mode (“NORMAL”, “SLEEP”, “LOOPBACK”, “LISTENONLY”, “CONFIG”, “POWERUP”, “ONE_SHOT”).

MCP2515.init_mask

init_mask(num, data, ext)

Initializes Masks.

Arguments:

  • num – 0 to set mask 0 on RX buffer, 1 to set mask 1 on RX buffer
  • data – Data Mask
  • ext – 0 for standard ID, 1 for Extended ID
MCP2515.init_filter

init_filter(num, data, ext)

Initializes Filters.

Arguments:

  • num – number of filter to be set in RX buffer (from 0 to 5)
  • data – Data Filter
  • ext – 0 for standard ID, 1 for Extended ID
MCP2515.send

send(canid, data, ext=None)

Sends CAN messages.

Arguments:

  • canid – ID of the CAN message (bytearray of 4 bytes)
  • data – Data to be sent (list of 8 bytes)
  • ext – 0 for standard ID, 1 for Extended ID (default None - auto detected)
MCP2515.recv

recv()

Receives CAN messages returnung CAN id value and related data message.

Returns canid, msg.