adafruit_mcp2515
¶
A CircuitPython library for working with the MCP2515 CAN bus controller using the
CircuitPython canio
API
- Author(s): Bryan Siepert
Implementation Notes¶
Hardware:
Software and Dependencies:
- Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases
- Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
-
class
adafruit_mcp2515.
MCP2515
(spi_bus, cs_pin, *, baudrate: int = 250000, loopback: bool = False, silent: bool = False, auto_restart: bool = False, debug: bool = False)¶ A common shared-bus protocol.
-
baudrate
¶ The baud rate (read-only)
-
bus_off_state_count
¶ Not supported by hardware. Raises an
AttributeError
if called
-
deinit
()¶ Deinitialize this object, freeing its hardware resources
-
deinit_filtering_registers
()¶ Clears the Receive Mask and Filter Registers
-
error_passive_state_count
¶ Not supported by hardware. Raises an
AttributeError
if called
-
error_warning_state_count
¶ Not supported by hardware. Raises an
AttributeError
if called
-
initialize
()¶ Return the sensor to the default configuration
-
listen
(matches=None, *, timeout: float = 10)¶ Start receiving messages that match any one of the filters.
Creating a listener is an expensive operation and can interfere with reception of messages by other listeners.There is an implementation-defined maximum number of listeners and limit to the complexity of the filters.
If the hardware cannot support all the requested matches, a ValueError is raised. Note that generally there are some number of hardware filters shared among all fifos.
A message can be received by at most one Listener. If more than one listener matches a message, it is undefined which one actually receives it.
An empty filter list causes all messages to be accepted.
Timeout dictates how long
receive()
will block.- Args:
- match (Optional[Sequence[Match]], optional): [description]. Defaults to None. timeout (float, optional): [description]. Defaults to 10.
- Returns:
- Listener: [description]
-
loopback
¶ True if the device was created in loopback mode, False otherwise. (read-only)
-
read_message
()¶ Read the next available message
Returns: The next available message or None if one is not available Return type: canio.Message
-
receive_error_count
¶ The number of receive errors (read-only). Increased for a detected reception error, decreased for successful reception. Limited to the range from 0 to 255 inclusive. Also called REC.
-
restart
()¶ If the device is in the bus off state, restart it.
-
send
(message_obj)¶ - Send a message on the bus with the given data and id. If the message could not be sent
- due to a full fifo or a bus error condition, RuntimeError is raised.
Parameters: message (canio.Message) – The message to send. Must be a valid canio.Message
-
silent
¶ True if the device was created in silent mode, False otherwise. (read-only)
-
state
¶ The current state of the bus. (read-only)
-
transmit_error_count
¶ The number of transmit errors (read-only). Increased for a detected transmission error, decreased for successful transmission. Limited to the range from 0 to 255 inclusive. Also called TEC.
-
unread_message_count
¶ The number of messages that have been received but not read with
read_message
Returns: The unread message count Return type: int
-
-
adafruit_mcp2515.
ReceiveBuffer
¶ alias of
adafruit_mcp2515.TransmitBuffer