And here this code does not work:
#include <mcp_can.h>
#include <SPI.h>
bool GABAR;
unsigned int CAN_ID;
byte Byte_01;
byte Byte_02;
byte Byte_03;
byte Byte_04;
byte Byte_05;
byte Byte_06;
byte Byte_07;
byte Byte_08;
const int SPI_CS_PIN= 9;
MCP_CAN CAN(SPI_CS_PIN);
void setup()
{
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(2, INPUT);
pinMode(8, INPUT);
// init serial
Serial.begin(115200);
while (CAN_OK != CAN.begin(CAN_1000KBPS))
{
delay(1);// ожидаем конекта
}
}
void loop()
{
//Плата:2
unsigned char len = 0;
byte buf[8];
if(CAN_MSGAVAIL == CAN.checkReceive()) // check if data coming
{
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
CAN_ID = CAN.getCanId();
Byte_01 = buf[0];
Byte_02 = buf[1];
Byte_03 = buf[2];
Byte_04 = buf[3];
Byte_05 = buf[4];
Byte_06 = buf[5];
Byte_07 = buf[6];
Byte_08 = buf[7];
}
SendCANFramesToSerial();
}
void SendCANFramesToSerial()
{
//Все адреса CAN ID должны быть переведены в HEX. Например : = 0х5DA,
//а информационные байты остаются как есть! Это нужно для получения правильных
//данных в файле описания.XML
byte buf[8];
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x186, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x18A, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x1B0, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x1F6, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x217, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x242, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x29A, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x29C, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x2BC, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x2C6, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x350, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x352, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x354, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x45C, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x4AC, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x4DE, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x500, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x511, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x552, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x55D, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x564, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x575, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x5D7, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x5DA, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x5DE, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x5DF, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x648, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x653, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x657, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x65C, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x666, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x66A, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x69F, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x7E0, buf);
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_03 & 0xff);
buf[3] = (Byte_04 & 0xff);
buf[4] = (Byte_05 & 0xff);
buf[5] = (Byte_06 & 0xff);
buf[6] = (Byte_07 & 0xff);
buf[7] = (Byte_08 & 0xff);
SendCANFrameToSerial(0x7E8, buf);
}
void SendCANFrameToSerial(unsigned long canFrameId, const byte* frameData)
{
// the 4 byte identifier at the beginning of each CAN frame
// this is required for RealDash to 'catch-up' on ongoing stream of CAN frames
const unsigned long serialBlockTag = 0x11223344;
Serial.write((const byte*)&serialBlockTag, 4);
//the CAN frame id number
Serial.write((const byte*)&canFrameId, 4);
// CAN frame payload
Serial.write(frameData, 8);
}