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

TWAI is not working for ESP32-S3 #1895

Closed
ProfFan opened this issue Aug 1, 2024 · 3 comments · Fixed by #1906
Closed

TWAI is not working for ESP32-S3 #1895

ProfFan opened this issue Aug 1, 2024 · 3 comments · Fixed by #1906
Labels
bug Something isn't working peripheral:twai TWAI peripheral

Comments

@ProfFan
Copy link
Contributor

ProfFan commented Aug 1, 2024

The TWAI peripheral does not work both with blocking and async mode.

Nothing is transmitted and received, transmitting always "succeed" even without nothing on the bus, which under normal TWAI mode should be a bus error.

@ProfFan
Copy link
Contributor Author

ProfFan commented Aug 1, 2024

A simple test program with transceivers and nothing on the CAN bus yields:

[INFO] - Transmitting a frame
[INFO] - CAN IS_BUS_OFF: false
[INFO] - CAN TX_ERROR: 0
[INFO] - Transmitted a frame
[INFO] - Transmitting a frame
[INFO] - CAN IS_BUS_OFF: false
[INFO] - CAN TX_ERROR: 0
<program stuck on `transmit_async`>

@SergioGasquez SergioGasquez added the peripheral:twai TWAI peripheral label Aug 5, 2024
@ProfFan
Copy link
Contributor Author

ProfFan commented Aug 5, 2024

I tested the CAN RX on a live bus (1Mbps) with transceiver. I confirmed that RX of the transceiver has continuous data, but a simple test program with no filter receiver nothing on the bus.

    // The speed of the CAN bus.
    const CAN_BAUDRATE: twai::BaudRate = twai::BaudRate::B1000K;

    // Begin configuring the TWAI peripheral. The peripheral is in a reset like
    // state that prevents transmission but allows configuration.
    let mut can_config = twai::TwaiConfiguration::new_async(
        peripherals.TWAI0,
        can_tx_pin,
        can_rx_pin,
        &clocks,
        CAN_BAUDRATE,
    );

    let mut can: Twai<_, Async> = can_config.start();

    let rx_data = can.receive_async().await;

        match rx_data {
            Ok(frame) => {
                defmt::info!("Received a frame:");
                print_frame(&frame);
            }
            Err(e) => {
                defmt::error!("Receive error: {:?}", defmt::Debug2Format(&e));
            }
        }

@ProfFan
Copy link
Contributor Author

ProfFan commented Aug 5, 2024

I tried whatever I can to debug this issue, the most like cause is the register blocks are not correctly configured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working peripheral:twai TWAI peripheral
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants