Hello community,
I successfully enabled CAN communication on my Tracker One SoM. Now I want an interrupt handler react to incoming CAN transmissions.
In setup
I am invoking interrupts(). Is that necessary at all?
After that I am initiating CAN connection with these lines of code:
MCP_CAN canInterface(CAN_CS, SPI1);
void can_init(void){
// Turn on CAN_5V power
pinMode(CAN_PWR, OUTPUT);
digitalWrite(CAN_PWR, HIGH);
// Set STBY low to enable transmitter and high-speed receiver
pinMode(CAN_STBY, OUTPUT);
digitalWrite(CAN_STBY, LOW);
// Enable the CAN interrupt pin as an input just in case
pinMode(CAN_INT, INPUT);
Log.info("Interrupt Attached: %d", attachInterrupt(CAN_INT, CAN_IRQHandler, CHANGE));
// Hardware reset the CAN controller. Not really necessary, but doesn't hurt.
pinMode(CAN_RST, OUTPUT);
digitalWrite(CAN_RST, LOW);
delay(100);
digitalWrite(CAN_RST, HIGH);
// Make sure the last parameter is MCP_20MHZ; this is dependent on the crystal
// connected to the CAN chip and it's 20 MHz on the Tracker SoM.
byte status = canInterface.begin(MCP_SIDL, CAN_500KBPS, MCP_20MHZ);
if(status == CAN_OK) {
Log.info("CAN initialization succeeded");
}
else {
Log.error("CAN initialization failed %d", status);
}
// Change to normal mode to allow messages to be transmitted. If you don't do this,
// the CAN chip will be in loopback mode.
canInterface.setMode(MCP_MODE_NORMAL);
}
and my handler looks like this:
void CAN_IRQHandler(void){
Log.info("CAN IRQ activated");
}
Can you guys see an issue with that code or if there’s something I am doing not correctly?
Thanks in advance!