canChannel
Add-On Required: This feature requires the MATLAB Support Package for Arduino Hardware add-on.
Description
This object represents a connection to the CAN channel through the specified device connected to the Arduino® hardware. To transmit and receive data from Arduino hardware through the CAN bus use Object Functions.
Creation
Syntax
Description
creates a CAN channel connected to the specified device.ch
= canChannel(arduinoObj
,device
)
creates a CAN channel connected to the MCP2515 chip with specified
ch
= canChannel(arduinoObj
,'MCP2515',ChipSelectPin
,InterruptPin
)ChipSelectPin
and InterruptPin
.
creates a CAN channel connected to the specified device with the specified additional
options.ch
= canChannel(arduinoObj
,device
,Name,Value
)
creates a CAN channel connected to the MCP2515 chip with specified
ch
= canChannel(arduinoObj
,'MCP2515',ChipSelectPin
,InterruptPin
,Name,Value
)ChipSelectPin
and InterruptPin
and the additional
options.
Input Arguments
Properties
Object Functions
Use these object functions to transmit and receive messages from the CAN bus.
Examples
Create Connection to CAN Channel on Shield
Create an arduino object
arduinoObj = arduino('COM24', 'Uno', 'Libraries', 'CAN')
arduinoObj = arduino with properties: Port: 'COM24' Board: 'Uno' AvailablePins: {'D2-D13', 'A0-A5'} AvailableDigitalPins: {'D2-D13', 'A0-A5'} AvailablePWMPins: {'D3', 'D5-D6', 'D9-D11'} AvailableAnalogPins: {'A0-A5'} AvailableI2CBusIDs: [0] Libraries: {'CAN', 'SPI'} Show all properties
Create a connection to the CAN channel on Sparkfun CAN-Bus Shield
ch = canChannel(arduinoObj,"Sparkfun CAN-Bus Shield")
ch = canChannel with properties: Device: 'Sparkfun CAN-Bus Shield' ProtocolMode: 'CAN' BusSpeed: 500000 Database: [] Show all properties Device: 'Sparkfun CAN-Bus Shield' ProtocolMode: 'CAN' BusSpeed: 500000 Database: [] OscillatorFrequency: 1.600000e+07 ChipSelectPin: "D9" InterruptPin: "D2"
Create Connection to CAN Channel on MCP2515
Create an arduino object
arduinoObj = arduino('COM24', 'Uno', 'Libraries', 'CAN')
arduinoObj = arduino with properties: Port: 'COM24' Board: 'Uno' AvailablePins: {'D2-D13', 'A0-A5'} AvailableDigitalPins: {'D2-D13', 'A0-A5'} AvailablePWMPins: {'D3', 'D5-D6', 'D9-D11'} AvailableAnalogPins: {'A0-A5'} AvailableI2CBusIDs: [0] Libraries: {'CAN', 'SPI'} Show all properties
Create a connection to the CAN channel on MCP2515
ch = canChannel(arduinoObj, "MCP2515", "D10", "D2")
ch = canChannel with properties: Device: 'MCP2515' ProtocolMode: 'CAN' BusSpeed: 500000 Database: [] Show all properties Device: 'MCP2515' ProtocolMode: 'CAN' BusSpeed: 500000 Database: [] OscillatorFrequency: 1.600000e+07 ChipSelectPin: "D10" InterruptPin: "D2"
Create Connection to CAN Channel on Shield with Specified Bus Speed
Create an arduino object
arduinoObj = arduino('COM24', 'Uno', 'Libraries', 'CAN')
arduinoObj = arduino with properties: Port: 'COM24' Board: 'Uno' AvailablePins: {'D2-D13', 'A0-A5'} AvailableDigitalPins: {'D2-D13', 'A0-A5'} AvailablePWMPins: {'D3', 'D5-D6', 'D9-D11'} AvailableAnalogPins: {'A0-A5'} AvailableI2CBusIDs: [0] Libraries: {'CAN', 'SPI'} Show all properties
Create a connection to the CAN channel on Sparkfun CAN-Bus Shield
ch = canChannel(arduinoObj,"Sparkfun CAN-Bus Shield", "BusSpeed", 500e3)
ch = canChannel with properties: Device: 'Sparkfun CAN-Bus Shield' ProtocolMode: 'CAN' BusSpeed: 500000 Database: [] Show all properties Device: 'Sparkfun CAN-Bus Shield' ProtocolMode: 'CAN' BusSpeed: 500000 Database: [] OscillatorFrequency: 1.600000e+07 ChipSelectPin: "D9" InterruptPin: "D2"
Create Connection to CAN Channel on MCP2515 with Specified Bus Speed
Create an arduino object
arduinoObj = arduino('COM24', 'Uno', 'Libraries', 'CAN')
arduinoObj = arduino with properties: Port: 'COM24' Board: 'Uno' AvailablePins: {'D2-D13', 'A0-A5'} AvailableDigitalPins: {'D2-D13', 'A0-A5'} AvailablePWMPins: {'D3', 'D5-D6', 'D9-D11'} AvailableAnalogPins: {'A0-A5'} AvailableI2CBusIDs: [0] Libraries: {'CAN', 'SPI'} Show all properties
Create a connection to the CAN channel on MCP2515
ch = canChannel(arduinoObj, "MCP2515", "D10", "D2", "OscillatorFrequency", 16e6, "BusSpeed", 500e3)
ch = canChannel with properties: Device: 'MCP2515' ProtocolMode: 'CAN' BusSpeed: 500000 Database: [] Show all properties Device: "MCP2515" ProtocolMode: "CAN" BusSpeed: 500000 Database: [] OscillatorFrequency: 1.600000e+07 ChipSelectPin: "D10" InterruptPin: "D2"
Version History
Introduced in R2020a
See Also
arduino
| read
| write
| canDatabase
(Vehicle Network Toolbox)