Connect SN65HVD230 to CAN bus 95 kbps

Shavo650
Posts: 3
Joined: Sat Dec 31, 2022 1:30 pm

Connect SN65HVD230 to CAN bus 95 kbps

Postby Shavo650 » 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

Code: Select all

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.

Code: Select all

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.

Code: Select all

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).

Code: Select all

#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:

Code: Select all

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...

Shavo650
Posts: 3
Joined: Sat Dec 31, 2022 1:30 pm

Re: Connect SN65HVD230 to CAN bus 95 kbps

Postby Shavo650 » Sat Jan 07, 2023 8:26 pm

My transceiver was broken from beginning. The below registers works great after replacing it.

Code: Select all

case (long)95E3:
      modifyRegister(REG_BTR1, 0x0f, 0x0c);
      modifyRegister(REG_BTR0, 0x3f, 25);
      break;

Who is online

Users browsing this forum: Google [Bot] and 139 guests