Hello, I have a very strange problem when using the mcp_can library.
The development board I use is arduino uno development board, mcp2515 module and mcp_canh function library.
my question:
When used, it reads the ID 0203 but it also reads the information 0x201, 0x202, 0x204
Here is the code I wrote.
#include <mcp_can.h>
#include <SPI.h>
// 定义 PID 控制相关参数
int setpoint = 0x2BC, Output = 0x2BC; // 设定值
float kp = 1; // 比例系数
float ki = 0.1; // 积分系数
float kd = 1; // 微分系数
float last_error = 0;
float integral = 0;
const int SPI_CS_PIN2 = 9; //电机1
MCP_CAN CAN2(SPI_CS_PIN2); //电机1
//PID
unsigned char buf2[8];
int rotor_angle1;
int torque1;
int rotor_speed1;
void setup() {
Serial.begin(9600);
if (CAN2.begin(MCP_ANY, CAN_1000KBPS, MCP_8MHZ) == CAN_OK) {
Serial.println("1MCP2515 Initialized Successfully!22222222");
CAN2.setMode(MCP_NORMAL);
} else {
Serial.println("1Error Initializing MCP2515...22");
}
}
unsigned char len = 0;
unsigned char buf[8];
int rotor_angle;
int torque;
int rotor_speed;
//测试得知 向c610发送扭矩 最大发送间隔为2500ms
void loop() {
delay(10);
CAN2.readMsgBuf(0x203, 8, buf1); // 读取CAN消息
rotor_angle1 = (buf1[0] << 8) | buf1[1]; // 转子机械角度
torque1 = (buf1[4] << 8) | buf1[5]; // 实际输出转矩
rotor_speed1 = (buf1[2] << 8) | buf1[3]; // 转子转速
Serial.println(rotor_speed1);
delay(2);
//}
}
This is part of my code to control the motor, and the problem is not only that the motor and the motor that communicate with can will stop rotating every time the motor data is read. At present, I know that the motor's motor will stop rotating when the can bus does not accept data for a long time (about 2000 milliseconds).
Can this situation be resolved? Thank you