uhi22 / wifican

Bridge between Wifi and CAN. Minimal variant of the ESP32RET. Using ESP32s3
19 stars 6 forks source link

How to set a different baud rate? #3

Closed zalexzperez closed 4 months ago

zalexzperez commented 4 months ago

Current baud rate is set to 500kbps apparently using the next line settings.canSettings[0].nomSpeed = 500000 What if I need a custom baudrate like 95kbps or 33.3kbps?

I already have the bit timing macro initializers from another project using TWAI: #define TWAI_TIMING_CONFIG_95KBITS() {.brp = 42, .tseg_1 = 15, .tseg_2 = 4, .sjw = 3, .triple_sampling = false} #define TWAI_TIMING_CONFIG_33k3KBITS() {.brp = 120, .tseg_1 = 15, .tseg_2 = 4, .sjw = 3, .triple_sampling = false}

zalexzperez commented 4 months ago

Well, I figured it out. It was unexpectedly easier. Simply edit esp32_can_builtin_local.cpp line 20 where twai_speed_cfg is. So, for 95kbps, we should have: twai_timing_config_t twai_speed_cfg = {.brp = 42, .tseg_1 = 15, .tseg_2 = 4, .sjw = 3, .triple_sampling = false};