Working on a small can project.
I have a uno v 1.6.7 and a Seeedstudio Can-Bus-Shield v 1.2
The code I'm using is just the example included with the library.
I have a device that sends a 2 bit can message to this Arduino/Seeed setup.
For Example I send a message 01 C0 (Hex)
In order for me to use this data how I need, I need the decimal conversion of 01CO
So I need 448 from 01 C0
So I need to combine the 2 bits then convert from hex to dec.
The can message changes all the time so it needs to calculate this each time.
After that I need to do some math to that number to get what I need.
Any Help would be great! Thanks
// demo: CAN-BUS Shield, receive data
#include <mcp_can.h>
#include <SPI.h>
unsigned char Flag_Recv = 0;
unsigned char len = 0;
unsigned char buf[8];
char str[20];
void setup()
{
CAN.begin(CAN_100KBPS); // init can bus : baudrate = 500k
attachInterrupt(0, MCP2515_ISR, FALLING); // start interrupt
Serial.begin(115200);
}
void MCP2515_ISR()
{
Flag_Recv = 1;
}
void loop()
{
if(Flag_Recv) // check if get data
{
Flag_Recv = 0; // clear flag
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
Serial.println("CAN_BUS GET DATA!");
Serial.print("data len = ");
Serial.println(len);
for(int i = 0; i<len; i++) // print the data
{
Serial.print(buf[i]);Serial.print("\t");
}
Serial.println();
}
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/