Send data to servo driver by CAN bus

#include <Arduino_CAN.h>    
#include <CanUtil.h>  
#include <R7FA4M1_CAN.h> 
#include <R7FA6M5_CAN.h>        
#include <SyncCanMsgRingbuffer.h>   

static uint32_t const CAN_ID = 0x601;

void setup() {
 
 Serial.begin(115200);
 
 while (!Serial) {}

  CAN.begin(CanBitRate::BR_125k);

  if (CAN.begin(CanBitRate::BR_125k)) {
    Serial.println("CAN.begin(...) Complished.");
    delay(100);
    Serial.println("CAN_BR is 125k.");
  }
 
 if (!CAN.begin(CanBitRate::BR_250k)) {
    Serial.println("CAN.begin(...) failed.");
  }
}

static uint32_t msg0_cnt = 0;
static uint32_t msg1_cnt = 0;
static uint32_t msg2_cnt = 0;

void loop(){
  uint8_t const msg0_data[] = { 0xCA, 0xFE, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
  memcpy((void *)(msg0_data + 4), &msg0_cnt, sizeof(msg0_cnt));
  CanMsg const msg0(CanStandardId(CAN_ID), sizeof(msg0_data), msg0_data);
  CAN.write(msg0);
  if (int const rc = CAN.write(msg0); rc < 0) {
    Serial.print("CAN.write(...) failed with error code ");
    Serial.println(rc);
  }
  msg0_cnt++;
  delay(1000);
}

I need to use Arduino Uno R4 (CAN bus has been embedded onboard) to communicate with servo driver.
The program is compiled successfully but the serial port monitor always displays the message that the transmission failed.My guess is that maybe I am using the function that sends the command incorrectly.
问题2
Thank you very much for your any advice on my problem!!!!

what is the meaning of error-code 60003?

I will take a SWAG and say it is not able to transmit a valid message because it is not getting an acknowledge. This causes its counter to counting out and your software is detecting the error and giving you the information. One of the biggest causes is the wrong baud. It is set wrong or your not set for the correct crystal frequency.

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