diff --git a/sufst-controller/can.cpp b/sufst-controller/can.cpp index cf6a339ef593ff74aa2633df7b90458b9b8e1729..781ede0c0a45454b0e7816a53aa80852507fa87a 100644 --- a/sufst-controller/can.cpp +++ b/sufst-controller/can.cpp @@ -45,6 +45,13 @@ extern void ecuCanMsg0x2008(CanMsgTemplate *canMsg); extern void ecuCanMsg0x2009(CanMsgTemplate *canMsg); +static void canISR(); + +static void canISR() +{ + canSaveMsg(); +} + // ECU can messages function pointers for calling the corresponding function when that msg is seen. // Used in function canParseRxMsg. void @@ -68,6 +75,8 @@ uint8_t canBegin() pinMode(CAN_INT_PIN, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(CAN_INT_PIN), canISR, FALLING); + // Initialize the Arduino CAN class with slave select pin. can.init_CS(CAN_CS_PIN); @@ -145,41 +154,6 @@ void canAddTxRequest(CanMsgTemplate *canMsg) cirBufferWrite(&canTxCirBuffer, canMsg); } -// External interrupt currently only designed to work with atmega 2560 -#if !defined(__AVR_ATmega2560__) -#error "PLATFORM NOT SUPPORTED CURRENTLY" -#endif // !defined(atmega2560) - -#if CAN_INT_PIN != 2 -#error "CAN_INT_PIN CHANGED FROM 2" -#endif //CAN_INT_PIN != 2 - -void canBeginExtInterrupt() -{ - noInterrupts(); - - // On the mega 2560 pin 2 is external interrupt 4 - EIMSK &= ~(1 << INT4); - - EICRB &= ~(1 << ISC41); - //EICRB &= ~(1 << ISC40); - - EIMSK |= (1 << INT4); - - interrupts(); -} - -ISR(INT4_vect) { - - noInterrupts(); - - lastCanMsgRecTimeMs = millis(); - - canSaveMsg(); - - interrupts(); -} - void canParseRxMsg(CanMsgTemplate *canMsg) { if ((canMsg->id >= 0x2000) && (canMsg->id <= 0x200A)) { diff --git a/sufst-controller/can.h b/sufst-controller/can.h index f01e8d423c31abbafd908ba2eb8693023d1ebd67..5725d557a268aa12c323047285ad3ee848a976e3 100644 --- a/sufst-controller/can.h +++ b/sufst-controller/can.h @@ -9,7 +9,7 @@ // CAN_INT_PIN MUST BE 2 #define CAN_INT_PIN 2 -#define CAN_CS_PIN 9 +#define CAN_CS_PIN 10 #define CAN_RX_BUFFER_LEN 32 #define CAN_TX_BUFFER_LEN 32