-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CAN example #312
Comments
TL;DR: Remove the Long story: you are mis-interpreting the example. The example calls |
Thanks for your reply. It worked on Friday - code below. fn main() {
// It is necessary to call this function once. Otherwise some patches to the runtime
// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71
esp_idf_sys::link_patches();
esp_idf_svc::log::EspLogger::initialize_default();
info!("Hello, world!");
let peripherals = Peripherals::take().unwrap();
let pins = peripherals.pins;
let filter = can::config::Filter::standard_allow_all();
let timing = can::config::Timing::B1M;
let config = can::config::Config::new().filter(filter).timing(timing);
let mut can = can::CanDriver::new(peripherals.can, pins.gpio27, pins.gpio26, &config).unwrap();
loop {
if let Ok(rx_frame) = can.receive(1000) {
info!("rx {:}:", rx_frame);
}
}
} |
I ran into this as well and figured it out by explicitly specifying I want the trait method, thus opting into the nonblocking API. nb::block!(embedded_can::nb::Can::transmit(&mut can, &tx_frame)).unwrap();
if let Ok(rx_frame) = nb::block!(embedded_can::nb::Can::receive(&mut can)) {
log::info!("rx {:}:", rx_frame);
} As it stands, the documented "hello world" example for this crate seems to be broken :/ |
Would you clarify what exactly is broken w.r.t. the documented "hello world" example? |
I copied the example from the crate documentation and added use embedded_can::nb::Can;
use embedded_can::Frame;
use embedded_can::StandardId;
use esp_idf_hal::can;
use esp_idf_hal::prelude::*;
fn main() {
let peripherals = Peripherals::take().unwrap();
let pins = peripherals.pins;
// filter to accept only CAN ID 881
let filter = can::config::Filter::Standard {
filter: 881,
mask: 0x7FF,
};
// filter that accepts all CAN IDs
// let filter = can::config::Filter::standard_allow_all();
let timing = can::config::Timing::B500K;
let config = can::config::Config::new().filter(filter).timing(timing);
let mut can = can::CanDriver::new(peripherals.can, pins.gpio5, pins.gpio4, &config).unwrap();
let tx_frame =
can::Frame::new(StandardId::new(0x042).unwrap(), &[0, 1, 2, 3, 4, 5, 6, 7]).unwrap();
nb::block!(can.transmit(&tx_frame)).unwrap();
if let Ok(rx_frame) = nb::block!(can.receive()) {
info!("rx {:}:", rx_frame);
}
} Then I ran
Dependencies:
|
I think what you are saying is that this doc example does not compile out of the box, as it went out of date. Because we don't run Fair enough.. I've reopened the issue. Feel free to contribute a PR that fixes the example. ... and I hope you are not blocked by this. The example only needs a few minimal changes to compile. |
Hello.
Based on example I tried to compile it:
Error:
When I change calling receive method:
Error:
The text was updated successfully, but these errors were encountered: