ESP32-Arduino-CAN
ESP32-Arduino-CAN copied to clipboard
Wrong transmission speed on ESP32D0WDQ5 Wrover chip
We successfully tested ESP32-Arduino-CAN with 1 Mbit/s on an ESP32D0WDQ6 (Wroom, revision 1, WiFi, BT, Dual Core, Coding Scheme None, Auto-detected Flash size: 4MB).
But on a ESP32D0WDQ5 (Wrover, revision 1, WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None, Auto-detected Flash size: 8MB) the communication did not work and our oscilloscope showed a bitrate of 500 Kbit/s.
After fiddling around for hours, we found the following (dirty) adjustment to get it working: In CAN.c, where the baud rate pre-scaler (BRP) is computed, we set BRP and TSEG1 as follows (TSEG2 is already 1):
MODULE_CAN->BTR0.B.BRP = 1;
MODULE_CAN->BTR1.B.TSEG1 = 6;
We don't quite understand, how this works out to yield the correct frequency in the end. Sync bit, TSEG1 and TSEG2 sum to 8 time quanta. Pre-scaling it with 1 Mbit/s yields 8 Mbit/s. The APB clock frequency APB_CLK_FREQ
is 80,000,000, but maybe that value is wrong? (See https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/twai.html#bit-timing for documentation.)