Seeed_Arduino_CAN
Seeed_Arduino_CAN copied to clipboard
CAN.getCanId() gets the ID of the TX MSG insted of the RX MSG
I send a message periodically (100 Hz) with the CAN-SHIELD (MPC2515). In parallel, I execute the following function:
while (CAN_MSGAVAIL == CAN.checkReceive())
{
CanRxInterrupt();
//Serial.println("MSG detects on RX");
}
void CanRxInterrupt() {
unsigned int canId = CAN.getCanId();
unsigned char len;
unsigned char buf[8];
CAN.readMsgBuf(&len, buf);
Serial.println(canId, HEX);
CAN_MSGAVAIL == CAN.checkReceive()
works perfectly with an incoming message and CanRxInterrupt() is called when a MSG is incomming. However, the following line:
unsigned int canId = CAN.getCanId()
always returns the ID of the just periodically sent message and not that of the incoming message. Sommetimes when the incomming MSG ist sent with a verry high frequence i got the correct ID, but nearly never.
- OS: Windows 11, Arduino, VS Code