sandeepmistry / arduino-CAN

An Arduino library for sending and receiving data using CAN bus.
MIT License
684 stars 235 forks source link

SN65HVD230DR ESP32 not communicating #114

Open lolimpol opened 1 year ago

lolimpol commented 1 year ago

I have two of these boards: https://nl.aliexpress.com/item/1005002844175352.html

they communicate together like normal, using this code:

// Copyright (c) Sandeep Mistry. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#include <CAN.h>

void setup() {
  pinMode(23, OUTPUT);
  digitalWrite(23, LOW);
  Serial.begin(115200);
  while (!Serial);
  Serial.println("CAN Sender");
  // start the CAN bus at 500 kbps
  if (!CAN.begin(500E3)) {
    Serial.println("Starting CAN failed!");
    while (1);
  }
}

void loop() {
  // send packet: id is 11 bits, packet can contain up to 8 bytes of data
  Serial.print("Sending packet ... ");
  CAN.beginPacket(0x12);
  CAN.write('h');
  CAN.write('e');
  CAN.write('l');
  CAN.write('l');
  CAN.write('o');
  Serial.print(CAN.endPacket());

  Serial.println("done");
  delay(1000);
  // send extended packet: id is 29 bits, packet can contain up to 8 bytes of data
  Serial.print("Sending extended packet ... ");

  CAN.beginExtendedPacket(0xabcdef);
  CAN.write('w');
  CAN.write('o');
  CAN.write('r');
  CAN.write('l');
  CAN.write('d');
  int ERROR_CODE = CAN.endPacket(); // must be a int
Serial.print(ERROR_CODE); Serial.print('\t');
switch (ERROR_CODE) {
case 1: Serial.print("Buf sent!\r\n");
break;
case -1: Serial.print("Get tx buff time out!\r\n");
break;
case -2: Serial.print("Send msg timeout!\r\n");
break;
default: Serial.print("Buf send failed!\r\n");
}
  Serial.println("done");
  delay(1000);
}

I designed a light controller PCB, and I have 2 of these as well, they communicate without issue. here's the repository: https://oshwlab.com/pol.peerboom/patrol-lcu

Now whenever I try to make them communicate together it doesnt work. I tried desoldering the resistor on the RS pin, and soldered it to pin 23 on the development board ESP32, so when I pull it low in code, it should put them in the same mode. Any ideas? does it matter that they're slightly different models?

thanks!

silk-indus commented 11 months ago

I don't know if it is still a current question, bud I also had some problems with counterfeit SN65HVD230DR transceivers. Another problem I encountered was different bus frequency. Please check using of oscilloscope desired freq.