0

I am trying to read CAN bus from my car (my car use 95Kbps can speed). I use this library Link. To add custom CAN baud rate, added this

typedef enum {
    CAN_SPEED_100KBPS = 100,  /**< \brief CAN Node runs at 100kBit/s. */
    CAN_SPEED_125KBPS = 125,  /**< \brief CAN Node runs at 125kBit/s. */
    CAN_SPEED_200KBPS = 200,  /**< \brief CAN Node runs at 250kBit/s. */
    CAN_SPEED_250KBPS = 250,  /**< \brief CAN Node runs at 250kBit/s. */
    CAN_SPEED_500KBPS = 500,  /**< \brief CAN Node runs at 500kBit/s. */
    CAN_SPEED_800KBPS = 800,  /**< \brief CAN Node runs at 800kBit/s. */
    CAN_SPEED_1000KBPS = 1000 /**< \brief CAN Node runs at 1000kBit/s. */
    CAN_SPEED_95KBPS = 95 /**< \brief CAN Node runs at 95kBit/s. */ //This string I added
} CAN_speed_t;

And I use esp32can_basic.ino with two modifications

  1. Set speed
CAN_cfg.speed = CAN_SPEED_95KBPS;
  1. Delete writing
    if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    CAN_frame_t tx_frame;
    tx_frame.FIR.B.FF = CAN_frame_std;
    tx_frame.MsgID = 0x001;
    tx_frame.FIR.B.DLC = 8;
    tx_frame.data.u8[0] = 0x00;
    tx_frame.data.u8[1] = 0x01;
    tx_frame.data.u8[2] = 0x02;
    tx_frame.data.u8[3] = 0x03;
    tx_frame.data.u8[4] = 0x04;
    tx_frame.data.u8[5] = 0x05;
    tx_frame.data.u8[6] = 0x06;
    tx_frame.data.u8[7] = 0x07;
    ESP32Can.CANWriteFrame(&tx_frame);

But nothing work :( My hardware is ESP32-PICO-D4 and SN65HVD230 CAN Board. What have I done wrong?

UPD1 in CAN.c in int CAN_init() there are this strings

switch (CAN_cfg.speed) {
    case CAN_SPEED_1000KBPS:
        MODULE_CAN->BTR1.B.TSEG1 = 0x4;
        __tq = 0.125;
        break;

    case CAN_SPEED_800KBPS:
        MODULE_CAN->BTR1.B.TSEG1 = 0x6;
        __tq = 0.125;
        break;

    case CAN_SPEED_200KBPS:
        MODULE_CAN->BTR1.B.TSEG1 = 0xc;
        MODULE_CAN->BTR1.B.TSEG2 = 0x5;
        __tq = 0.25;
        break;

    default:
        MODULE_CAN->BTR1.B.TSEG1 = 0xc;
        __tq = ((float) 1000 / CAN_cfg.speed) / 16;
    }

I think this code calculate tq. "Nothing work" - no CAN codes read. I think I set wrong baud rate.

  • What's the purpose of the enum? If it serves as index in some look-up table then adding another item to it will screw everything up. Also, just adding another item to an enum won't magically give you the correct tq configurations for that baudrate. Also it isn't clear what "nothing work" means... do you get wrong baudrate, do you get error frames, what? – Lundin May 09 '22 at 08:28
  • I don't think your car has some CAN buses with 95kBit/s. Automotive engineers tend to be conservative, they will use standard baudrates: typically 125kBit/s, 250kBit/s or 500kBit/s. – Robert May 10 '22 at 06:10
  • @Robert, GM use no standard speeds, "MSCAN - Dual-wire, Medium Speed CAN-BUS, 95 kbps". [link](https://www.carmod.ru/img/opel/opcom/opcom_manual.pdf) _italic_ – Maxim Issaev May 10 '22 at 09:13

1 Answers1

0

TQ (Time Quanta) is like the Sampling rate at which this SP is taken, which is also between TSEG1 and TSEG2 First and second Segment.

You need to calculate this values (check here) for more infor and a calculator

lui
  • 76
  • 3