ESP32 and CAN (VD230)

OK, I'm trying to read data on a CAN bus with an ESP32 and a sn65hvd230 CAN transceiver, I've tried every library out there, tried swapping RX/TX pins, CANH/CANL pins, fiddling with bitrates, etc.. NOTHING will work, I've spent 2 days on this and I'm absolutely frustrated now.
I have an oscilloscope and I seem to be getting data on the CanRX pin

I have no problem doing this with my Leo and MCP2515/2551 breakout board.

Last library I used was this one GitHub - sandeepmistry/arduino-CAN: An Arduino library for sending and receiving data using CAN bus.
I used the examples from the library (modifying CAN and Serial baud rates to suit) and I can't receive a thing

Any ideas?

miwagner/ESP32-Arduino-CAN: An Arduino CAN-Bus library for ESP32 (github.com) for when using a ESP32.

1 Like

Thanks I've tried that one extensively.. no way to make it work.. seems like there's a lot of different ones based on it, I've tried them all!

As a note, it works for me.

#include <CAN_config.h>
#include <ESP32CAN.h>

CAN_device_t CAN_cfg;
setup()
{
CAN_cfg.speed = CAN_SPEED_1000KBPS;
  CAN_cfg.tx_pin_id = GPIO_NUM_12; // green wire
  CAN_cfg.rx_pin_id =  GPIO_NUM_13; // white wire
  CAN_cfg.rx_queue = xQueueCreate(3, sizeof(CAN_frame_t));
  //start CAN Module
  ESP32Can.CANInit();

 xTaskCreatePinnedToCore ( fSendCAN_Buss, "fSendCAN_Buss", TaskStack15K, NULL, Priority4, NULL, TaskCore0 );
  sema__Send_CAN_Bus = xSemaphoreCreateMutex();
  xSemaphoreGive ( sema__Send_CAN_Bus );
}

void fSendCAN_Buss( void *pvParameters )
{
  stuSERVO_Message pxServo_Message;
  for ( ;; )
  {
    xEventGroupWaitBits (eg, evtSendCAN_Buss, pdTRUE, pdTRUE, portMAX_DELAY);
    if ( xSemaphoreTake( sema__Send_CAN_Bus, xTicksToWait0 ) == pdTRUE ) // grab semaphore no wait
    {
      CAN_frame_t rx_frame;
      // Serial.println ( " fSendCAN_Buss 2 "  );
      if ( (CAN_cfg.rx_queue != NULL) && (uxQueueMessagesWaiting(CAN_cfg.rx_queue)) ) // if queue not null and something is waiting in queue
      {
        // Serial.println ( uxQueueMessagesWaiting(CAN_cfg.rx_queue) );
        if (xQueueReceive( CAN_cfg.rx_queue, &rx_frame , xTicksToWait0) == pdTRUE )
        {
          if ( rx_frame.MsgID == 2 )
          {
            // Serial.println ( rx_frame.data.u8[0] );
            if ( rx_frame.data.u8[0] == '6' )
            {
              EOT = false;
              // Serial.print ( " frame ID " );
              // Serial.print ( rx_frame.MsgID );
              // Serial.println ( "ACK" );
              //              rx_frame.FIR.B.FF = CAN_frame_std;
              //              rx_frame.MsgID = xServo_EOT.MsgID;
              //              rx_frame.FIR.B.DLC = xServo_EOT.DLC;
              //              rx_frame.data.u8[0] = xServo_EOT.Servo_EOT;
              //              rx_frame.data.u8[1] = xServo_EOT.p4; // send all '0'
              //              rx_frame.data.u8[2] = xServo_EOT.p4;
              //              rx_frame.data.u8[3] = xServo_EOT.p4;
              //              rx_frame.data.u8[4] = xServo_EOT.p4;
              //              rx_frame.data.u8[5] = xServo_EOT.p4;
              //              rx_frame.data.u8[6] = xServo_EOT.p4;
              //              rx_frame.data.u8[7] = xServo_EOT.p4;
              //              ESP32Can.CANWriteFrame(&rx_frame);
              // Serial.println ( " sent Servo controller ack " );
              //              vTaskDelay( pdMS_TO_TICKS( 6 ) );
            }
            //            if (rx_frame.data.u8[0] = '3')
            //              {
            //                EOT = false;
            //              }
            if ( rx_frame.data.u8[0] == '4' )
            {
              //                          rx_frame.FIR.B.FF = CAN_frame_std;
              //                          rx_frame.MsgID = xServo_EOT.MsgID;
              //                          rx_frame.FIR.B.DLC = xServo_EOT.DLC;
              //                          rx_frame.data.u8[0] = '4';
              //                          rx_frame.data.u8[1] = xServo_EOT.p4;
              //                          rx_frame.data.u8[2] = xServo_EOT.p4;
              //                          rx_frame.data.u8[3] = xServo_EOT.p4;
              //                          rx_frame.data.u8[4] = xServo_EOT.p4;
              //                          rx_frame.data.u8[5] = xServo_EOT.p4;
              //                          rx_frame.data.u8[6] = xServo_EOT.p4;
              //                          rx_frame.data.u8[7] = xServo_EOT.p4;
              //                          ESP32Can.CANWriteFrame(&rx_frame);
              // Serial.println ( "InitComplete ack " );
              EOT = false;
              xSemaphoreGive ( sema_HexaPodAdjustment ); // begin walking forward task
            }
          } // if ( rx_frame.MsgID == 2 )
        } // if (xQueueReceive( CAN_cfg.rx_queue, &rx_frame , xTicksToWait5) == pdTRUE )
      } // if ( (CAN_cfg.rx_queue != NULL) && (uxQueueMessagesWaiting(CAN_cfg.rx_queue)) )
      //      // ack the initialization
      if ( xQueueReceive ( xQ_SERVO_Message, &pxServo_Message, QueueReceiveDelayTime ) == pdTRUE )
      {
        rx_frame.FIR.B.FF = CAN_frame_std;
        rx_frame.MsgID = pxServo_Message.MsgID;
        rx_frame.FIR.B.DLC = pxServo_Message.DLC;
        rx_frame.data.u8[0] = pxServo_Message.Instruction;
        rx_frame.data.u8[1] = pxServo_Message.p1;
        rx_frame.data.u8[2] = pxServo_Message.p2;
        rx_frame.data.u8[3] = pxServo_Message.p3;
        rx_frame.data.u8[4] = pxServo_Message.p4; // end of torque to position
        rx_frame.data.u8[5] = pxServo_Message.p5;
        rx_frame.data.u8[6] = pxServo_Message.p6;
        rx_frame.data.u8[7] = pxServo_Message.p7;
        //                Serial.print ( " message in sendCanBus " );
        //                Serial.print ( ", " );
        //                Serial.print ( rx_frame.data.u8[0] );
        //                Serial.print ( ", " );
        //                Serial.print ( rx_frame.data.u8[1] );
        //                Serial.print ( ", " );
        //                Serial.print (rx_frame.data.u8[2] );
        //                Serial.print ( ", " );
        //                Serial.print ( rx_frame.data.u8[3] );
        //                Serial.print ( ", " );
        //                Serial.print ( rx_frame.data.u8[4] );
        //                Serial.println ( " message end." );
        ESP32Can.CANWriteFrame(&rx_frame);
      }
      //
      xSemaphoreGive ( sema__Send_CAN_Bus );
      ////
      // Serial.print( "fSendCAN_Buss " );
      // Serial.print(uxTaskGetStackHighWaterMark( NULL ));
      // Serial.println();
      // Serial.flush();
    }  // if ( xSemaphoreTake( sema__Send_CAN_Bus, xTicksToWait0 ) == pdTRUE ) // grab semaphore no wait
  } // the for loop
  vTaskDelete( NULL );
} // void fSendCAN_Buss( void *pvParameters )
/////////////////////////////////////////////////////

I'll try the same libraries with entirely different hardware and see if there's a problem in my hardware.. I have several of each device.. give that a shot!

I know this is a little old, but I'm having the same problem. Did anyone get this to work with a VD230? Like Rx7Man I've tried several libraries.
Downloading the VD230 spec and testing the logic, it appears to differ markedly from the spec. For example, if the D pin is ground the R pin floats. That is also not in the spec.

I got the transceiver from Amazon. An interesting thing is the labelling on the VD230 wears off. If they were really from TI, I don't think it would do that. I've ordered a different transceiver but it will take several weeks to arrive.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.