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

ESP32-C3: TWAI broken when using GPIO1 for RX #1207

Closed
bjoernQ opened this issue Feb 27, 2024 · 4 comments
Closed

ESP32-C3: TWAI broken when using GPIO1 for RX #1207

bjoernQ opened this issue Feb 27, 2024 · 4 comments
Labels
bug Something isn't working chip:esp32c3 Issue related to ESP32-C3 chip examples There is a problem with one or more of the examples peripheral:twai TWAI peripheral

Comments

@bjoernQ
Copy link
Contributor

bjoernQ commented Feb 27, 2024

While testing #1196 it was found that TWAI is apparently broken for ESP32-C3 while it's still working for ESP32-S3

@MabezDev MabezDev added bug Something isn't working examples There is a problem with one or more of the examples labels Feb 27, 2024
@jessebraham jessebraham added the peripheral:twai TWAI peripheral label Feb 28, 2024
@bjoernQ
Copy link
Contributor Author

bjoernQ commented Feb 29, 2024

After a lot of fiddling, it seems that for whatever reason things don't work for me when using GPIO 1 as RX.
Using GPIO 2 however works fine apparently. Would be good if anyone else could check if GPIO1 is fine for them

@bjoernQ bjoernQ changed the title ESP32-C3: TWAI broken ESP32-C3: TWAI broken when using GPIO1 for RX Apr 5, 2024
zephyr-atomi pushed a commit to zephyr-atomi/esp32-weather-kit that referenced this issue May 9, 2024
Please don't use GPIO 1 for RX, due to issue here: esp-rs/esp-hal#1207
@tom-borcin tom-borcin added the chip:esp32c3 Issue related to ESP32-C3 chip label Aug 13, 2024
@msvisser
Copy link

I have been playing with Rust on the ESP32-C3 and I ran into the same problem where GPIO1 does not work as RX for the TWAI peripheral. I already had some code written in C using the ESP-IDF which did work on my hardware, so I knew this was a software issue.

To determine where the issue is, I started comparing the registers of the peripherals after they were initialized by C and by Rust. I noticed that the TWAI_CLOCK_OFF bit in the TWAI_CLOCK_DIVIDER_REG was not set by esp-hal but was set by the ESP-IDF. I then added some code to TwaiConfiguration::new_internal to set this bit, and that fixed the issue for me!

// Disable CLKOUT
T::register_block()
    .clock_divider()
    .write(|w| w.clock_off().bit(true));

I will try to open a pull request tomorrow to incorporate this change and fix the issue.

@ProfFan
Copy link
Contributor

ProfFan commented Aug 15, 2024

@msvisser Is this still the case after #1906 is merged? In theory the choice of which GPIO should not matter at all as they all go through the GPIO matrix.

@msvisser
Copy link

Okay I have checked again, and it seems like #1906 did fix the problem. I was tripped up by #1929, because before it was merged the peripheral was always initialized in listen only mode, while I was trying to transmit first before receiving. When I forked the repo to implement my fix it suddenly started working because I was using a newer version of esp-hal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working chip:esp32c3 Issue related to ESP32-C3 chip examples There is a problem with one or more of the examples peripheral:twai TWAI peripheral
Projects
Archived in project
Development

No branches or pull requests

6 participants