ESP32 CAN bus errors at 95 kbps
Shavo650 opened this issue · 1 comments
Hi all!
I want to use ESP32 + SN65HVD230 in my car. I can't find good parameters to set CAN bus bitrate to 95 kbps. I already did it for Arduino + MCP2515 and everything works fine, but not for ESP32. After i connect ESP32 to CAN bus then i got a lot of errors and weird things happen, because of wrong bit timing. I tried to use calculator https://www.kvaser.com/support/calculators/bit-timing-calculator/ (80 Mhz frequency for SJA1000, 95kbps, 0,5 % allowed error. So i edited ESP32SJA1000.cpp:
This is original
case (long)100E3:
modifyRegister(REG_BTR1, 0x0f, 0x0c);
modifyRegister(REG_BTR0, 0x3f, 24);
break;
So i edited BTR_0 and BTR_1 values to match these from calculator.
case (long)95E3:
modifyRegister(REG_BTR1, 0x0f, 0x7b);
modifyRegister(REG_BTR0, 0x3f, 13);
break;
I tried also values like below, because someone wrote they are right.
case (long)95E3:
modifyRegister(REG_BTR1, 0x0f, 0x0c);
modifyRegister(REG_BTR0, 0x3f, 25);
break;
And here is interesting thing. I found here at github code for official ESP32 TWAI library, where author used these values in his project. And it works perfect when i tried to use example code to receive messages from bus (0 errors).
#define CAN_TIMING_CONFIG_95KBITS() {.brp = 42, .tseg_1 = 15, .tseg_2 = 4, .sjw = 3, .triple_sampling = false}
So i tried to find values of T1, T2 and sjw in calculator and put corresponding BTR_0 and BTR_1 but it didn't work too:
case (long)95E3:
modifyRegister(REG_BTR1, 0x0f, 0x3d);
modifyRegister(REG_BTR0, 0x3f, 95);
break;
Can you help me please ? I don't want to switch to other library and i'm out of idea at the moment...
The problem was because broken transceiver. I've got new already and these settings works:
case (long)95E3: modifyRegister(REG_BTR1, 0x0f, 0x0c); modifyRegister(REG_BTR0, 0x3f, 25); break;