Crates.io | can2040 |
lib.rs | can2040 |
version | 0.1.5 |
source | src |
created_at | 2023-12-08 18:12:59.416266 |
updated_at | 2024-04-30 06:54:08.623857 |
description | A Can2040 port for Rust. |
homepage | |
repository | https://github.com/atomi-ai/can2040-rust |
max_upload_size | |
id | 1062306 |
size | 1,229,675 |
This is a port of can2040 in C. Based on this, we can enable CAN on RP2040 with Rust.
RP2040 GPIO 26 <=> CAN RX
RP2040 GPIO 27 <=> CAN TX
RP2040 GND <=> CAN GND
RP2040 3V3 <=> CAN 3V3
CAN CAN-H <=> USB CAN-H
CAN CAN-L <=> USB CAN-L
The demo is run on Linux, using a relatively low baud rate of 10_000. After debugging, you can choose a higher baud rate yourself.
Plug the USB into your computer and make sure the corresponding socket is enabled (here it corresponds to socket can0).
sudo ip link set down can0 && \
sudo ip link set can0 type can bitrate 10000 && \
sudo ip link set up can0
Then, run the following command to monitor the messages on the CAN bus for debugging:
candump can0
Make sure all the wiring is correct, and if you adjust the GPIOs, make sure the corresponding GPIOs in the code are adjusted as well. Once everything is ready, you can run the following command, and you should see RP2040 continuously sending CAN frames to the USB:
cargo run --release --example can2040_demo
Run the following command on your computer and make sure the RP2040 console window receives the information:
cansend can0 123#DEADBEEF12345678