Skip to content

CAN issue on C6 #472

@m-dahl

Description

@m-dahl

Hi. I am trying to get CAN working on a C6 devkitC-1 but not getting anywhere. Both sends and receives hang and then return ESP_ERR_TIMEOUT. It works on a C3 devkit I have but I would like to use the C6 if possible.

What I have done is:

  • Generated a crate using cargo generate esp-rs/esp-idf-template cargo selected C6 from the list.
  • Added the following code to main:
use esp_idf_hal::prelude::*;
use esp_idf_hal::can;
use log::*;

fn main() {
    esp_idf_sys::link_patches();
    esp_idf_svc::log::EspLogger::initialize_default();

    let peripherals = Peripherals::take().unwrap();
    let pins = peripherals.pins;

    let filter = can::config::Filter::standard_allow_all();
    let timing = can::config::Timing::B250K;
    let config = can::config::Config::new().filter(filter).timing(timing);

    let mut can = can::CanDriver::new(peripherals.can, pins.gpio4, pins.gpio5, &config).unwrap();

    can.start().unwrap();

    loop {
        let r = can.receive(1000);
        if let Ok(rx_frame) = &r {
            info!("echoing {}", rx_frame);
            if let Err(e) = can.transmit(&rx_frame, 10) {
                info!("tx error: {}", e);
            }
        } else if let Err(e) = &r {
            info!("rx error {:}", e);
        }
    }
}
  • Verified that the above code and connections to tranceiver and other test node work using a C3-DevkitC-02 (I simply replace the devkit on my breadboard, leaving all other connections). No issues there, the program echoes the packages as expected.
  • I have tried to set up the CAN driver with config::Mode::NoAck and sent frames with can::Flags::SelfReception. Also works.

I realize that the issue here is a bit fuzzy and could very well be something else related to my CAN bus setup but I am asking anyway in case I am missing something simple. Could there be some configuration step that I have missed for the C6? With the C3 it was plug and play. Can my transceiver (SN65HVD251P) be incompatible with the C6? I noticed that the C6 has two CAN drivers but in my code I don't actively select one of them. Perhaps I need to? Grateful for any pointers.

[EDIT] I just did a quick test with esp-hal (i.e not idf) and using that I do receive and can send CAN frames with the C6. So I guess I am missing something on the software side, or there is a bug in the bindings. (This example works: https://github.com/esp-rs/esp-hal/blob/main/examples/src/bin/embassy_twai.rs, modified to not use no_tranceiver and my GPIOs).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions