2023-10-13 09:35:33 [显示全部楼层]
494浏览
查看: 494|回复: 1

[求助] CAN通信-程序编译成功但仍无法正常发送指令

[复制链接]
  1. #include <Arduino_CAN.h>   
  2. #include <CanUtil.h>  
  3. #include <R7FA4M1_CAN.h>
  4. #include <R7FA6M5_CAN.h>        
  5. #include <SyncCanMsgRingbuffer.h>   
  6. static uint32_t const CAN_ID = 0x601;
  7. void setup() {
  8. Serial.begin(115200);
  9. while (!Serial) {}
  10.   CAN.begin(CanBitRate::BR_125k);
  11.   if (CAN.begin(CanBitRate::BR_125k)) {
  12.     Serial.println("CAN.begin(...) Complished.");
  13.     delay(100);
  14.     Serial.println("CAN_BR is 125k.");
  15.   }
  16. if (!CAN.begin(CanBitRate::BR_250k)) {
  17.     Serial.println("CAN.begin(...) failed.");
  18.   }
  19. }
  20. static uint32_t msg0_cnt = 0;
  21. static uint32_t msg1_cnt = 0;
  22. static uint32_t msg2_cnt = 0;
  23. void loop(){
  24.   uint8_t const msg0_data[] = { 0xCA, 0xFE, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
  25.   memcpy((void *)(msg0_data + 4), &msg0_cnt, sizeof(msg0_cnt));
  26.   CanMsg const msg0(CanStandardId(CAN_ID), sizeof(msg0_data), msg0_data);
  27.   CAN.write(msg0);
  28.   if (int const rc = CAN.write(msg0); rc < 0) {
  29.     Serial.print("CAN.write(...) failed with error code ");
  30.     Serial.println(rc);
  31.   }
  32.   msg0_cnt++;
  33.   delay(1000);
  34. }
复制代码
[size=15.008px]需要用Arduino Uno R4(板载CAN总线)跟伺服驱动器通信。
[size=15.008px]程序编译成功,但串行端口监视器始终显示传输失败的消息。[size=15.008px]

[size=15.008px]我觉得可能是发送命令的函数没用对,希望有大佬能给指点一下!!!!

FriOctober-202310132887..png

DFEDU  高级技师

发表于 2023-10-13 11:50:44

接线拍照
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail