enableCAN - Enable CAN interface - MATLAB (original) (raw)
Enable CAN interface
Since R2021b
Syntax
Description
enableCAN([raspiObj](#mw%5F44172c18-241a-4244-a84e-e68796e9ca8a))
enables thecan0
interface for MCP2515 CAN controller.
enableCAN([raspiObj](#mw%5F44172c18-241a-4244-a84e-e68796e9ca8a),[devicename](#bt%5Fcxbh-1-i2cBusSpeed))
. Enables CAN interface for the specified device. The CAN controller can only be set to MCP2515
. To disable CAN, use the disableCAN function.
enableCAN([raspiObj](#mw%5F44172c18-241a-4244-a84e-e68796e9ca8a),[devicename](#bt%5Fcxbh-1-i2cBusSpeed),[interfacename](#mw%5F6c49e000-4eb7-46e0-8449-7ed64ba6e272))
enables the CAN object for the specified interface and device. To disable CAN, use the disableCAN function.
enableCAN([raspiObj](#mw%5F44172c18-241a-4244-a84e-e68796e9ca8a),[devicename](#bt%5Fcxbh-1-i2cBusSpeed),[interfacename](#mw%5F6c49e000-4eb7-46e0-8449-7ed64ba6e272), [oscillatorFrequency](#mw%5F4817f85b-2c4c-41ae-877e-3de3289b4814))
enables the CAN object when the interface name, device name, and oscillator frequency is set. To disable CAN, use the disableCAN function.
enableCAN([raspiObj](#mw%5F44172c18-241a-4244-a84e-e68796e9ca8a),[devicename](#bt%5Fcxbh-1-i2cBusSpeed),[interfacename](#mw%5F6c49e000-4eb7-46e0-8449-7ed64ba6e272), [oscillatorFrequency](#mw%5F4817f85b-2c4c-41ae-877e-3de3289b4814),[interruptPin](#mw%5F38f2f511-d44b-40b7-9e29-5143117cf199))
enables the CAN object for the specified interrupt pin, interface, device, and oscillator frequency. To disable CAN, use the disableCAN function.
Examples
Enable CAN Object
Create a Raspberry PiĀ® object. The available CAN interfaces do not show until you enable the CAN object.
raspiObj = raspi("192.168.1.101","pi","raspberry")
raspiObj = raspi with properties:
DeviceAddress: '192.168.1.101'
Port: 18734
BoardName: 'Raspberry Pi 3 Model B+'
AvailableLEDs: {'led0'}
AvailableDigitalPins: [4,5,6,12,13,14,15,16,17,18,19,
20,21,22,23,24,25,26,27]
AvailableSPIChannels: {'CE0','CE1'}
AvailableI2CBuses: {'i2c-0','i2c-1'}
AvailableWebcams: {}
I2CBusSpeed: 100000
AvailableCANInterfaces: {}
supported peripherals
Enable the CAN interface with default properties.
SPI channels are inaccessible if you enable the CAN interface forMCP2515
controllers. Reboot the Raspberry Pi to apply the changes.
system(raspiObj, 'sudo reboot').
Connection to SSH server at 192.168.1.101
is terminated. Clear the hardware communication object and re-create it to establish the connection.
clear raspiObj raspiObj = raspi("192.168.1.101","pi","raspberry")
A CAN object is enabled.
raspiObj =
raspi with properties:
DeviceAddress: '192.168.1.101'
Port: 18734
BoardName: 'Raspberry Pi 3 Model B+'
AvailableLEDs: {'led0'}
AvailableDigitalPins: [4,5,6,10,12,13,14,15,16,17,18,19,
20,21,22,23,24,25,26,27]
AvailableSPIChannels: {'CE1'}
AvailableI2CBuses: {'i2c-0','i2c-1'}
AvailableWebcams: {}
I2CBusSpeed: 100000
AvailableCANInterfaces: {"can0"}
Supported peripherals
Input Arguments
Connection to a Raspberry Pi hardware board, specified as a raspi object.
Data Types: object
The default CAN controller available is MCP2515
.
Example: MCP2515
Data Types: string
CAN interface, specified as either can0
orcan1
.
Example: can0
Data Types: string
Note
Enabling can1
interface will also enablecan0
if it is not enabled before.
Frequency of the oscillator crystal in the shield, specified as8
or 12
or 16
MHz.
Example: 16
Data Types: double
The interrupt pin of the Raspberry Pi that connect with CAN shield, specified as a number between4
and 25
, included.
Example: 25
Data Types: double
Version History
Introduced in R2021b