https://github.com/coryjfowler/MCP_CAN_lib/blob/master/examples/CAN_loopback/CAN_loopback.ino我使用这个库来实现CAN总线,我使用环回模式的例子使用一个单arduino连接到MCP2525 CAN传输器。但是我得到的错误是MCP2515还没有初始化,消息正在传输。我如何解决这个错误?
的#include 的#include // CAN TX变量无符号长prevTX = 0;//变到最后一次执行时间存储const的无符号整型invlTX = 1000;//一个第二间隔恒定字节数据[] = {和0xAA,0x55的,0×01,为0x10,0xFF时,0×12,0x34,0x56储存};//通用CAN数据发送// CAN RX变量长期无符号整型rxId;无符号的字符len个;无符号字符RXBUF; [8]//串行输出字符串缓冲炭msgString [128];// CAN0 INT和CS的#define CAN0_INT 2 //设置INT到销2 MCP_CAN CAN0(10);//设置CS到销10的空隙的设置(){Serial.begin(115200);// CAN在500,000BPS运行; 115,200BPS is SLOW, not FAST, thus 9600 is crippling. // Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled. if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK) Serial.println("MCP2515 Initialized Successfully!"); else Serial.println("Error Initializing MCP2515..."); // Since we do not set NORMAL mode, we are in loopback mode by default. //CAN0.setMode(MCP_NORMAL); pinMode(CAN0_INT, INPUT); // Configuring pin for /INT input Serial.println("MCP2515 Library Loopback Example..."); } void loop() { if(!digitalRead(CAN0_INT)) // If CAN0_INT pin is low, read receive buffer { CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s) if((rxId & 0x80000000) == 0x80000000) // Determine if ID is standard (11 bits) or extended (29 bits) sprintf(msgString, "Extended ID: 0x%.8lX DLC: %1d Data:", (rxId & 0x1FFFFFFF), len); else sprintf(msgString, "Standard ID: 0x%.3lX DLC: %1d Data:", rxId, len); Serial.print(msgString); if((rxId & 0x40000000) == 0x40000000){ // Determine if message is a remote request frame. sprintf(msgString, " REMOTE REQUEST FRAME"); Serial.print(msgString); } else { for(byte i = 0; i= invlTX){ // Send this at a one second interval. prevTX = millis(); byte sndStat = CAN0.sendMsgBuf(0x100, 8, data); if(sndStat == CAN_OK) Serial.println("Message Sent Successfully!"); else Serial.println("Error Sending Message..."); } }