RealDashCAN

Greetings. I hope everyone knows how to use a translator)
So here. In the test sketch, we are asked to transfer up to 8 bytes in each frame, but think about it, because this sketch allows sending each of 8 bytes to any frame, essentially) is that right?
But the problem is that if you send a byte in this way, for example, temperature in one frame, and 2 bytes of revolutions in another frame, then the first bytes of each frame will intersect.
-How does this appear on the panel?
-Yes very simple. The values ​​jump anywhere and any way, the arrows twitch, the scales move with a shake.
And you can’t remove this effect either by high-quality soldering or by noise-protected USB lanyards, or by changing the controller itself))
This is all gone.
The secret is terribly simple. I do not know why Jani still has not fixed it, because I wrote to him about this phenomenon and also wrote about the solution to the problem.
Oh well, on this forum you can find the truth …
You need to conclude and check the condition for sending each frame in the “if” cycle, then this terrible effect will no longer bother you.
Use on health)))

Example:
if (CAN_ID == 0x186)
{
buf [0] = (RPM & 0xff);
buf [1] = (COOLANT & 0xff);
buf [2] = (buf [2] & 0xff);
buf [3] = (buf [3] & 0xff);
buf [4] = (buf [4] & 0xff);
buf [5] = (buf [5] & 0xff);
buf [6] = (buf [6] & 0xff);
buf [7] = (buf [7] & 0xff);
SendCANFrameToSerial (1000, buf);
}

Forum is currently English only.

Fixed

Your code and explanation makes absolutely no sense to me. Hope it is useful to someone.

Anyway, I made minor updates to the Arduino examples on GitHub. Tried to add some more comments and improved frame receive code in 2way example. Also, I tried to minimize the references to little/big endian, since it seems to be confusing to some.

I just wanted to focus on the fact that if you modify the code a bit, you can avoid unnecessary interference, I did not want to blame you for something … excuse me if I do something wrong …

In addition to everything, the translator is extremely informative in transmitting my messages, so it’s very difficult to convey the sacred meaning))

No offense taken, just trouble to understand what you mean. It could be language barrier.

What are you, nor any insults! I have been communicating with you by e-mail for more than 2 years. This is only a pleasure))
, let me lay out all my code with comments … Maybe then I can find a common language))

#include <mcp_can.h>

#include <mcp_can_dfs.h>

#include <SPI.h>

byte NTEMPHight;
byte NTEMPLow;
byte TOPLHight;
byte TOPLLow;
bool DMASL;
bool ZAKB;
bool IGN;
bool BK;
bool RBEZ;
bool RUCHN;
bool UTORM;
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= 10;
MCP_CAN CAN(SPI_CS_PIN);
byte _WordToBytes_1_HBO = 0;
byte _WordToBytes_1_LBO = 0;
byte _WordToBytes_2_HBO = 0;
byte _WordToBytes_2_LBO = 0;
void setup()
{
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(2, INPUT);
pinMode(8, INPUT);
pinMode(9, INPUT);

// init serial
Serial.begin(115200);

while (CAN_OK != CAN.begin(CAN_500KBPS))
{
delay(1);// ожидаем конекта
}
}
void loop()
{int _tempVariable_int;





//Плата:1
_tempVariable_int = (analogRead (1));
_WordToBytes_1_HBO = highByte(_tempVariable_int);
_WordToBytes_1_LBO = lowByte(_tempVariable_int);
_tempVariable_int = (map(( (analogRead (0))), (250), (785), (50), (0)));
_WordToBytes_2_HBO = highByte(_tempVariable_int);
_WordToBytes_2_LBO = lowByte(_tempVariable_int);
NTEMPHight = _WordToBytes_1_HBO;
NTEMPLow = _WordToBytes_1_LBO;
TOPLHight = _WordToBytes_2_HBO;
TOPLLow = _WordToBytes_2_LBO;
DMASL = !( (digitalRead (6)));
ZAKB = (digitalRead (2));
IGN = (digitalRead (9));
BK = !( (digitalRead (8)));
RBEZ = !( (digitalRead (7)));
RUCHN = !( (digitalRead (4)));
UTORM = !( (digitalRead (5)));
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()
{



byte buf[8];


//Please note that before sending a message I check whether my MCP2515 is on the identifier now, if I don’t do this focus then the 8 bytes received from mcp2515 can go to any of the send addresses) which will cause a twitching effect and cause artifacts on the dashboard (unpredictable data jumps) people write about this and in other branches of this forum this is obvious)))

//rpm
if (CAN_ID == 0x186)
{
buf[0] = (Byte_01 & 0xff);
buf[1] = (Byte_02 & 0xff);
buf[2] = (Byte_06 & 0xff); //TPS
buf[3] = (Byte_07 & 0xff);
SendCANFrameToSerial(390, buf);
}


// Speed ​​AUTO divided by 10 000 Since
// centimeters per hour come from the car
if (CAN_ID == 0x217)
{
buf[0] = (Byte_04 & 0xff);
buf[1] = (Byte_05 & 0xff);
buf[2] = (Byte_06 & 0xff);
SendCANFrameToSerial(535, buf);
}
//ICE temperature “-40”
if (CAN_ID == 0x5DA)
{
buf[0] = (Byte_01 & 0xff);
SendCANFrameToSerial(1498, buf);
}
//Battery voltage “/10”
if (CAN_ID == 0x4AC)
{
buf[0] = (Byte_02 & 0xff);
SendCANFrameToSerial(1196, buf);
}
//SHINE
if (CAN_ID == 0x5DE)
{
buf[0] = (Byte_01 & 0xff); //левый поворот
buf[1] = (Byte_01 & 0xff); //правый поворот
buf[2] = (Byte_01 & 0xff); //дальний свет
buf[3] = (Byte_01 & 0xff); //габариты бит 02
buf[4] = (Byte_01 & 0xff); //ближний
//buf[5] = (Byte_01 & 0xff); //аварийка
buf[6] = (Byte_01 & 0xff); //ПТФ
buf[7] = (Byte_01 & 0xff); //ЗТФ

SendCANFrameToSerial(1502, buf);
}

//Reverse
if (CAN_ID == 0x648)
{
buf[0] = (Byte_07 & 0xff);
SendCANFrameToSerial(1608, buf);
}

//MILEAGE

if (CAN_ID == 0x5D7)
{
buf[0] = (Byte_03 & 0xff);
buf[1] = (Byte_04 & 0xff);
buf[2] = (Byte_05 & 0xff);
buf[3] = (Byte_06 & 0xff);
SendCANFrameToSerial(1495, buf);
}

//DOORS
if (CAN_ID == 0x5DE)
{
buf[0] = (Byte_02 & 0xff); //ВОДИТЕЛЬ 3й бит
buf[1] = (Byte_02 & 0xff); //ПАССАЖИР 1й бит
SendCANFrameToSerial(1505, buf);
}

//HEATING AND CLUTCH
if (CAN_ID == 0x5DD)
{
buf[0] = (Byte_03 & 0xff); // обогрев 3й бит
buf[1] = (Byte_03 & 0xff); // сцепление 5й бит
SendCANFrameToSerial(1501, buf);
}

// PETROL

buf[0] = (TOPLHight & 0xff);
buf[1] = (TOPLLow & 0xff);
SendCANFrameToSerial(2001, buf);

// OUTDOOR TEMPERATURE

buf[0] = (NTEMPHight & 0xff);
buf[1] = (NTEMPLow & 0xff);
SendCANFrameToSerial(2002, buf);

// ANALOGUE VALUES

buf[0] = (DMASL & 0xff);
buf[1] = (ZAKB & 0xff);
buf[2] = (IGN & 0xff);
buf[3] = (BK & 0xff);
buf[4] = (RBEZ & 0xff);
buf[5] = (RUCHN & 0xff);
buf[6] = (UTORM & 0xff);
SendCANFrameToSerial(2003, 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);

}