I am attempting to interface an Arduino Mega 2560 with a system of four Black Jaguar motor controllers connected in CAN. I'm using the CAN shield from SeeedStudios to accomplish this.
The way Jaguars in CAN mode are configured, you must send a message every 100 ms to the network to keep the link active. However, I'm also getting input from Serial to another Arduino as well as sending other commands to the Jaguars, but not regularly enough to specifically time it out.
Is it possible to have the link message sent asynchronously in the background while I perform other code? I have looked into timers and interrupts, however I am unsure if this would truly solve the issue considering I have other processes that take more than 100 ms to complete.
Here's my loop statement:
loop() {
CAN.sendMsgBuf(HEARTBEAT,1,0,volModeEnable); //HEARTBEAT keeps CAN link active
setVoltage(3,.5); //Sets voltage of Motor by percent
setVoltage(4,.5);
setVoltage(6,.5);
setVoltage(8,.5);
//GrabFromSerial(); Takes longer than 100ms
//Control Statement for Additional Commands goes here... (also necessary to be > 100ms)
}