I have a MCP2515 CANshield connected to an Uno.
I wrote a code that runs fine when connected to my car.
But when running the code outside the car it gets stuck on the “CAN.endPacket();” command.
I’m afraid my code getting stuck if there will be some connection problem in the car.
I could not find how to add a timeout to this command.
#include <CAN.h>
void setup() {
Serial.begin(9600);
Serial.println("Hi");
if (!CAN.begin(1000E3)) {
Serial.println("Starting CAN failed!");
while (1);
}
Serial.println("CAN connected");
}
void loop() {
CAN.beginPacket(0x7df, 8);
CAN.write(0x02); // number of additional bytes
CAN.write(0x01); // show current data
CAN.write(0x0d); // car speed
Serial.print("this works");
CAN.endPacket();
Serial.print("never getting here");
}