I have checked to make sure the circuit, baud rate, mghz, pin usage, and connections should be correct. I am using an Arduino Uno R3, a Globe Motors EPS system, and the CAN-BUS Shield DEV-13262 from Sparkfun to try and send a message. I keep getting exit flag=7 for the first 3 attempts, and then it switches to exit flag=6 for the rest. Is there some error in how I am trying to send the message? Any help or suggestions are appreciated.
dataArray.ino (1.38 KB)
system
April 5, 2018, 9:06pm
2
Your code was small enough to post inline.
#include <inttypes.h>
#include <mcp_can.h>
#include <SPI.h>
int32_t cf20=pow(2,20);
int16_t cf8=pow(2,8);
unsigned char m=3;
unsigned char blank=0;
float var1=1.25;
float var2=0;//-1;
unsigned char data[8]={};//0x02,0x00 /*(Unused)*/, 0x02,0x01, 0x01 , 0x05 /*(previous 4), (var1)*/, 0x00, 0x00};
MCP_CAN CAN0(10);
//byte data2[]={var1,var2};
void setup() {
Serial.begin(230400);
// Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
if (CAN0.begin(MCP_ANY, CAN_250KBPS, MCP_16MHZ) == CAN_OK){
Serial.println("MCP2515 Initialized Successfully!");
}
else {
Serial.println("Error Initializing MCP2515...");
}
CAN0.setMode(MCP_NORMAL);
}
union a_tag{
int32_t var;
byte dat[4];
} a;
union b_tag{
int16_t var;
byte dat[2];
} b;
//byte sndStat = 1;
void loop() {
// put your main code here, to run repeatedly:
a.var=round(var1*cf20);
b.var=round(var2*cf8);
data[0]=m;
data[1]=blank;
for (int d=0; d<4; d++){
data[d+2]=a.dat[3-d];
}
data[6]=b.dat[1];
data[7]=b.dat[0];
/*for (int i=2; i<6; i++){
Serial.println(data[i]);
} */
byte sndStat = CAN0.sendMsgBuf(0x18FF00F9, 1, sizeof(data), data);
if (sndStat == CAN_OK) {
Serial.println("Message Sent Successfully!");
} else {
Serial.println("Error Sending Message...");
Serial.print("Error Code: "); Serial.println(sndStat);
}
delay(100);
}
Post links to the hardware, not descriptions of it. Post links to the libraries you are using.