Custom can reader(ESP32)

There is no can adapter that supports LS can in the manual you created, so I’m trying to make a custom reader using esp32 and SN65HVD230. After writing the code, the computer gets the value on the serial monitor, but the realdash doesn’t get any value when connected.

How should I solve it?

#include <ACAN_ESP32.h>

const int ledPin = 2; // LED 핀 번호 (ESP32의 기본 LED 핀은 GPIO 2)

void setup() {
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT); // LED 핀을 출력으로 설정

  ACAN_ESP32_Settings settings(100000UL);
  
  // Default Tx: GPIO4, Rx: GPIO5
  settings.mRxPin = GPIO_NUM_17;
  settings.mTxPin = GPIO_NUM_16;

  const uint32_t ret = ACAN_ESP32::can.begin(settings);
    
  if (ret == 0) {    
    Serial.println("CAN Configuration OK!");
  } else {
    Serial.print("CAN Configuration error 0x");
    Serial.println(ret, HEX);    
  }
}

void loop() {
  CANMessage frame;

  // 수신된 CAN 메시지가 있는 경우
  bool messageReceived = ACAN_ESP32::can.receive(frame);
  
  if (messageReceived) {
    // LED를 깜박임
    digitalWrite(ledPin, HIGH);  // LED 켜기
    delay(100);                  // 100ms 대기
    digitalWrite(ledPin, LOW);   // LED 끄기

    // "CAN 44 프레임" 형식으로 변환하여 출력
    Serial.print("44 33 22 11 "); // 고정된 헤더 출력

    // CAN 프레임 ID 출력 (리틀 엔디안 형식)
    uint32_t canID = frame.id;
    Serial.printf("%02X %02X %02X %02X ", 
                  canID & 0xFF, 
                  (canID >> 8) & 0xFF, 
                  (canID >> 16) & 0xFF, 
                  (canID >> 24) & 0xFF);

    // 데이터 출력 (8바이트 고정)
    for (int i = 0; i < 8; i++) {
      if (i < frame.len) {
        Serial.printf("%02X", frame.data[i]);
      } else {
        Serial.print("00"); // 남은 바이트는 0으로 패딩
      }
      if (i < 7) {
        Serial.print(" ");
      }
    }
    Serial.println();
  } else {
    Serial.println("No message received");
  }

  // 약간의 지연을 추가하여 계속해서 메시지를 수신할 수 있도록 함
  delay(1000); // 지연 시간을 늘려 메시지 수신 상태를 명확히 파악
}

What connection type you are using on RealDash? I’m not familiar with the format that is used on your code snippet.

Also, sending messages like ‘No message received’ into the serial will cause RealDash to stop communication and reconnect.

I used 'Adapters(CAN/LIN) → RealDash CAN → Serial USB.

There are no letters coming out of the can monitor.

Yes, the data you are sending to serial on your example is not RealDash CAN data. See documentation of RealDash CAN protocol and a Arduino example here:

RealDash-extras/RealDash-CAN at master · janimm/RealDash-extras · GitHub

Please check if I understand well.

If CAN ID is 668 and data is 11, 22, 33, 44, 55, 66, 77, 88

"44 33 22 11 68 06 00 00 11 22 33 44 55 66 77 88 "

Is it right that it should be printed like this?

you were told “look at the documentation”… there is ready-made code there.


static byte combuf[8];

void SendCANFrameToSerial()
{ 
  memcpy(combuf, &YourData, 8);
  SendCANFrameToSerial(0x7001, combuf);
} 

void SendCANFrameToSerial(unsigned long canFrameId, const byte* frameData)
{
  const byte SerialBlockTag[4] = { 0x44, 0x33, 0x22, 0x11 };
  Serial.write(SerialBlockTag, 4);
  Serial.write((const byte*)&canFrameId, 4);
  Serial.write(frameData, 8);
}
1 Like