Skip to content
Snippets Groups Projects
Commit bd3e71fc authored by nrs1g15's avatar nrs1g15
Browse files

Added arduino interrupt

parent 74b130df
No related branches found
No related tags found
No related merge requests found
...@@ -45,6 +45,13 @@ extern void ecuCanMsg0x2008(CanMsgTemplate *canMsg); ...@@ -45,6 +45,13 @@ extern void ecuCanMsg0x2008(CanMsgTemplate *canMsg);
extern void ecuCanMsg0x2009(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. // ECU can messages function pointers for calling the corresponding function when that msg is seen.
// Used in function canParseRxMsg. // Used in function canParseRxMsg.
void void
...@@ -68,6 +75,8 @@ uint8_t canBegin() ...@@ -68,6 +75,8 @@ uint8_t canBegin()
pinMode(CAN_INT_PIN, INPUT_PULLUP); pinMode(CAN_INT_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(CAN_INT_PIN), canISR, FALLING);
// Initialize the Arduino CAN class with slave select pin. // Initialize the Arduino CAN class with slave select pin.
can.init_CS(CAN_CS_PIN); can.init_CS(CAN_CS_PIN);
...@@ -145,41 +154,6 @@ void canAddTxRequest(CanMsgTemplate *canMsg) ...@@ -145,41 +154,6 @@ void canAddTxRequest(CanMsgTemplate *canMsg)
cirBufferWrite(&canTxCirBuffer, 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) void canParseRxMsg(CanMsgTemplate *canMsg)
{ {
if ((canMsg->id >= 0x2000) && (canMsg->id <= 0x200A)) { if ((canMsg->id >= 0x2000) && (canMsg->id <= 0x200A)) {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
// CAN_INT_PIN MUST BE 2 // CAN_INT_PIN MUST BE 2
#define CAN_INT_PIN 2 #define CAN_INT_PIN 2
#define CAN_CS_PIN 9 #define CAN_CS_PIN 10
#define CAN_RX_BUFFER_LEN 32 #define CAN_RX_BUFFER_LEN 32
#define CAN_TX_BUFFER_LEN 32 #define CAN_TX_BUFFER_LEN 32
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment