Hi. For three months I have been trying to friend mcp2515 to send data from arduino to PLC unitronics v570. The data is coming, we are transmitting pt100 sensors. But sometimes we see this picture:
The data goes and becomes 145.0 for literally a couple of seconds. Which causes a crash at the station and it stops.
The cause has not been determined for a month now.
Principle of exchange: Array of 127 data from sensors
PLC sends us for example 0, we send data from 0 array. and when it comes 1 ->1 and so on 127 times.
It should be noted that we have a backup channel of exchange via ethernet and here on it such problems are not observed. I understand that it is faster and so on, but here is such a problem. Maybe there are some ideas to solve this problem
(procedur send data)
if (CAN.checkReceive() == CAN_MSGAVAIL) {
CAN.readMsgBuf(&canId, &len, received_data); // Читаем данные
mi_pos = received_data[0];
bool valid_mi_pos = (mi_pos >= 0) && (mi_pos < 125) && (mi_pos % 4 == 0);
if (valid_mi_pos) {
// Отправляем текущее значение из массива MI
short int value = MI[mi_pos]; // Берем текущее значение
uint8_t pos = 0; // выбираем, куда в can_data поместить значение (возможные значения: 0, 2, 4, 6)
memcpy(can_data + pos, &value, sizeof(short int));
value = MI[mi_pos + 1]; // выбираем, показания датчика MAX
pos = 2; // выбираем, куда в can_data поместить значение (возможные значения: 0, 2, 4, 6)
memcpy(can_data + pos, &value, sizeof(short int));
value = MI[mi_pos + 2]; // выбираем, показания датчика MAX
pos = 4; // выбираем, куда в can_data поместить значение (возможные значения: 0, 2, 4, 6)
memcpy(can_data + pos, &value, sizeof(short int));
value = MI[mi_pos + 3]; // выбираем, показания датчика MAX
pos = 6; // выбираем, куда в can_data поместить значение (возможные значения: 0, 2, 4, 6)
memcpy(can_data + pos, &value, sizeof(short int));
// Отправляем данные
if (CAN.sendMsgBuf(mi_pos, 0, 8, can_data) == CAN_OK) {
;
} else {
//Serial.println("Send error");
}
}
}
}
