Skip to content
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 issue on C6 #472

Open
m-dahl opened this issue Aug 13, 2024 · 0 comments
Open

CAN issue on C6 #472

m-dahl opened this issue Aug 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@m-dahl
Copy link

m-dahl commented Aug 13, 2024

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).

@Vollbrecht Vollbrecht added the bug Something isn't working label Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

2 participants