Connect SN65HVD230 to CAN bus 95 kbps
Posted: Sat Dec 31, 2022 1:41 pm
Hi all!
I use libraries from https://github.com/sandeepmistry/arduino-CAN .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/calculat ... alculator/ (80 Mhz frequency for SJA1000, 95kbps, 0,5 % allowed error. So i edited ESP32SJA1000.cpp:
This is original
So i edited BTR_0 and BTR_1 values to match these from calculator.
I tried also values like below, because someone wrote they are right.
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).
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:
Can you help me please ? I don't want to switch to other library and i'm out of idea at the moment...
I use libraries from https://github.com/sandeepmistry/arduino-CAN .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/calculat ... alculator/ (80 Mhz frequency for SJA1000, 95kbps, 0,5 % allowed error. So i edited ESP32SJA1000.cpp:
This is original
Code: Select all
case (long)100E3:
modifyRegister(REG_BTR1, 0x0f, 0x0c);
modifyRegister(REG_BTR0, 0x3f, 24);
break;
Code: Select all
case (long)95E3:
modifyRegister(REG_BTR1, 0x0f, 0x7b);
modifyRegister(REG_BTR0, 0x3f, 13);
break;
Code: Select all
case (long)95E3:
modifyRegister(REG_BTR1, 0x0f, 0x0c);
modifyRegister(REG_BTR0, 0x3f, 25);
break;
Code: Select all
#define CAN_TIMING_CONFIG_95KBITS() {.brp = 42, .tseg_1 = 15, .tseg_2 = 4, .sjw = 3, .triple_sampling = false}
Code: Select all
case (long)95E3:
modifyRegister(REG_BTR1, 0x0f, 0x3d);
modifyRegister(REG_BTR0, 0x3f, 95);
break;