I'm using this library on an esp32 wroom32d, 8mb.
https://github.com/sdp8483/ESP32-Arduino-CAN
I'm using it at 1mbit, and converting data to display on an LCD. Some data comes in quicker than others but it still feels like there is lag there compared to 500k.
My code in loop()
if (ESP32CAN_OK == ESP32Can.CANReadFrame(&rx_frame)) { /* only print when CAN message is received*/ processdata(rx_frame); }
processdata interprets the ID which tells it what data it is and displays it.
I'm stumped as to how to diagnose and am needing some help.
Esp32 canbus slow at 1mbit?
-
- Posts: 168
- Joined: Sun May 22, 2022 2:42 pm
Re: Esp32 canbus slow at 1mbit?
Assuming you have already modified the most important performance settings for CAN (CPU speed max, tick clock 1000 and CAN irq handler in IRAM)… at CAN speeds, the impact of printing to UART is huge. I'd remove all printing code and just keep a packet counter, so you can measure how many packets per second you receive. Test that with different CAN speeds. Note that the Arduino abstraction might come with another performance hit, so you might want to cross-test with a pure ESP-IDF project.
That said, the CAN controller in the ESP32 family is based on a pretty old design. It has a tiny hardware buffer, so you really need to pick up your frames from the bus as fast as possible, otherwise you're losing them.
That said, the CAN controller in the ESP32 family is based on a pretty old design. It has a tiny hardware buffer, so you really need to pick up your frames from the bus as fast as possible, otherwise you're losing them.
Re: Esp32 canbus slow at 1mbit?
So I havent made any changes other than... as far as CPU speed, it should be 240mhz. I'm using PlatformIO and VSCode so I think by default when I selected the esp32 it had 240mhz setup.
When you're talking about IRAM, is it as simple as me adding IRAM_ATTR to my parsing logic? or do I need to do that before?
Tick clock - not sure where to check this.
When you're talking about IRAM, is it as simple as me adding IRAM_ATTR to my parsing logic? or do I need to do that before?
Tick clock - not sure where to check this.
-
- Posts: 168
- Joined: Sun May 22, 2022 2:42 pm
Re: Esp32 canbus slow at 1mbit?
IRAM for the CAN irq handler is two-fold, one is a setting in the sdkconfig, the other is when setting the TWAI flags in code. As you're using the Arduino abstraction, I'm not sure if this is done already. Tick clock to 1000 is another sdkconfig setting, but IIRC that's probably also default in Arduino.
Re: Esp32 canbus slow at 1mbit?
Ok, so I went back to the miwagner version of the library and got it working at 1mbit. Messed with recieve buffers and it made a difference. Now I'm wondering where to update the rx_buffer on the new library that I referenced earlier...
Re: Esp32 canbus slow at 1mbit?
Well, I reverted back to the ESP32CAN library:
https://github.com/sdp8483/ESP32-Arduino-CAN
there is still a delay. I updated the miwagner to work at 1000mbits but it also has the same issue. I am stumped as to where to debug.
I'm experimenting with TWAI_MODE_LISTEN_ONLY but when I do that I receive the same data over and over.
https://github.com/sdp8483/ESP32-Arduino-CAN
there is still a delay. I updated the miwagner to work at 1000mbits but it also has the same issue. I am stumped as to where to debug.
I'm experimenting with TWAI_MODE_LISTEN_ONLY but when I do that I receive the same data over and over.
-
- Posts: 1
- Joined: Mon Apr 15, 2024 6:08 pm
Re: Esp32 canbus slow at 1mbit?
Hi, as it happens I am currently writing my Bachelor's thesis on CAN bus for home automation and ran into similar findings. So I had to make an account and join the conversation . I was testing the bus speeds with ESP32 and a custom transceiver module with the SN65HVD230 which resulted in the chart below. These times are however with some overhead of starting and ending the communication session with some back and forth frames. I just went back and confirmed that it adds about 0.25 seconds across the board. But since it is a constant overhead it doesn't affect the result which is that I got diminishing returns starting from 500mbit/s bit rate. I think that probably the controller is not up for these higher speeds because the transceiver is built for 1mbit/s rates, but since I do not have time to confirm this it will remain hypothetical for now. I would be interested if you get something similar, however, if you have time. Would be interesting to compare.themagicm wrote: ↑Wed Mar 13, 2024 3:30 amWell, I reverted back to the ESP32CAN library:
https://github.com/sdp8483/ESP32-Arduino-CAN
there is still a delay. I updated the miwagner to work at 1000mbits but it also has the same issue. I am stumped as to where to debug.
I'm experimenting with TWAI_MODE_LISTEN_ONLY but when I do that I receive the same data over and over.
- Attachments
-
- speed_vs_time.png (57.42 KiB) Viewed 1694 times
Who is online
Users browsing this forum: No registered users and 62 guests