I have a mega and a Seeed CAN BUS v2 shield to get the data from a battery BMS.
I know the Can Id's sent and that they are sent every 2 seconds.
0x359, 0x351, 0x355 , 0x356, 0x35C, 0x35E
The problem is I am missing some of the data. If I run the attached sketch I get the following;
14:55:35.061 -> Standard ID: 0x359 DLC: 7 Data: 0x00 0x00 0x00 0x00 0x01 0x50 0x4E
14:55:35.061 -> Standard ID: 0x351 DLC: 8 Data: 0x14 0x02 0x72 0x01 0x72 0x01 0xC2 0x01
14:55:35.061 -> Standard ID: 0x35E DLC: 8 Data: 0x50 0x59 0x4C 0x4F 0x4E 0x20 0x20 0x20
14:55:35.061 -> Standard ID: 0x355 DLC: 4 Data: 0x3F 0x00 0x64 0x00
14:55:37.016 -> Standard ID: 0x359 DLC: 7 Data: 0x00 0x00 0x00 0x00 0x01 0x50 0x4E
14:55:37.016 -> Standard ID: 0x351 DLC: 8 Data: 0x14 0x02 0x72 0x01 0x72 0x01 0xC2 0x01
14:55:37.016 -> Standard ID: 0x35E DLC: 8 Data: 0x50 0x59 0x4C 0x4F 0x4E 0x20 0x20 0x20
14:55:37.016 -> Standard ID: 0x355 DLC: 4 Data: 0x3F 0x00 0x64 0x00
Any data from 0x356, 0x35C is not there. If I limit the sketch to only print out for
if (rxId == 0x356 || rxId == 0x35C )
I will get;
14:59:17.435 -> Standard ID: 0x356 DLC: 6 Data: 0x39 0x13 0xFB 0xFF 0xC9 0x00
14:59:17.481 -> Standard ID: 0x35C DLC: 2 Data: 0xC0 0x00
14:59:17.481 -> Standard ID: 0x35E DLC: 8 Data: 0x50 0x59 0x4C 0x4F 0x4E 0x20 0x20 0x20
14:59:19.532 -> Standard ID: 0x356 DLC: 6 Data: 0x38 0x13 0xFB 0xFF 0xC9 0x00
14:59:19.532 -> Standard ID: 0x35C DLC: 2 Data: 0xC0 0x00
14:59:19.532 -> Standard ID: 0x35E DLC: 8 Data: 0x50 0x59 0x4C 0x4F 0x4E 0x20 0x20 0x20
The data is being received. Any Ideas?
I'm guessing I need to store it and then process.
// demo: CAN-BUS Shield, receive data with check mode
// send data coming to fast, such as less than 10ms, you can use this way
// loovee, 2014-6-13
#include <SPI.h>
// For Arduino MCP2515 Hat:
// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;
const int CAN_INT_PIN = 2;
#include "mcp2515_can.h"
mcp2515_can CAN(SPI_CS_PIN); // Set CS pin
void setup() {
SERIAL_PORT_MONITOR.begin(115200);
while (CAN_OK != CAN.begin(CAN_500KBPS)) { // init can bus : baudrate = 500k
SERIAL_PORT_MONITOR.println("CAN init fail, retry...");
delay(100);
}
SERIAL_PORT_MONITOR.println("CAN init ok!");
}
void loop() {
long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
if (CAN_MSGAVAIL == CAN.checkReceive()) { // check if data coming
CAN.readMsgBufID(&rxId, &len, rxBuf); // read data, len: data length, buf: data buffer
{
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 < len; i++)
{
sprintf(msgString, " 0x%.2X", rxBuf[i]);
Serial.print(msgString);
}
/*
unsigned long canId = CAN.getCanId();
SERIAL_PORT_MONITOR.println("-----------------------------");
SERIAL_PORT_MONITOR.print("Get data from ID: 0x");
SERIAL_PORT_MONITOR.println(canId, HEX);
for (int i = 0; i < len; i++) { // print the data
SERIAL_PORT_MONITOR.print(buf[i], HEX);
SERIAL_PORT_MONITOR.print("\t");
}
*/
SERIAL_PORT_MONITOR.println();
}
}
}
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/