Difference between revisions of "CAN bus"
Jump to navigation
Jump to search
(Created page with "== Enable CAN == * Check if drivers iniatialized properly using <code>lsmod | grep can</code> and <code>dmesg | grep can</code>. Results should be: : <syntaxhighlight lang="ba...") |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| + | The following instructions assume that the user is connected over SSH or use a terminal in a remote desktop. | ||
| + | |||
== Enable CAN == | == Enable CAN == | ||
| − | * Check if drivers iniatialized properly using | + | * Check if drivers iniatialized properly using <code>dmesg | grep can</code>. Results should include: |
| − | : | ||
| − | |||
| − | |||
| − | |||
: <syntaxhighlight lang="bash">$ dmesg | grep can | : <syntaxhighlight lang="bash">$ dmesg | grep can | ||
| − | [ | + | [ 1.651756] mcp251x spi0.0 can0: MCP2515 successfully initialized. |
| − | [ | + | [ 1.898432] can: controller area network core (rev 20120528 abi 9) |
| + | [ 1.898528] can: raw protocol (rev 20120528) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
* To turn on the can0 interface: | * To turn on the can0 interface: | ||
Latest revision as of 17:08, 29 October 2021
The following instructions assume that the user is connected over SSH or use a terminal in a remote desktop.
Enable CAN
- Check if drivers iniatialized properly using
dmesg | grep can. Results should include:
$ dmesg | grep can [ 1.651756] mcp251x spi0.0 can0: MCP2515 successfully initialized. [ 1.898432] can: controller area network core (rev 20120528 abi 9) [ 1.898528] can: raw protocol (rev 20120528)
- To turn on the can0 interface:
sudo ip link set can0 type can bitrate 1000000 sudo ip link set can0 up
- Check that the interrupt got enabled using
sudo cat /proc/interrupts | grep mcp(interrupt does not show up until the link is up):
$ sudo cat /proc/interrupts | grep mcp 133: 2 0 0 0 GPIO 34 Edge mcp251x
Loopback test
- Loopback mode allows to test if CAN is working properly. To enable it:
sudo ip link set can0 down sudo ip link set can0 type can loopback on sudo ip link set can0 type can bitrate 1000000 sudo ip link set can0 up
- Two terminals are required to test:
- First terminal:
cansend can0 001#1122334455667788
- Second terminal:
candump can0
- If the loopback test is successful, it should show:
candump can0 can0 001 [8] 11 22 33 44 55 66 77 88 can0 001 [8] 11 22 33 44 55 66 77 88
- Turn off the loopback:
sudo ip link set can0 down sudo ip link set can0 type can loopback off sudo ip link set can0 type can bitrate 1000000
Send and receive data
- To receive data:
candump can0
- To send single frame:
cansend can0 001#1122334455667788
- To send extended frame (used by ArduPilot):
cansend can0 00100000#1122334455667788