diff --git a/due_obd2/due_obd2.ino b/due_obd2/due_obd2.ino index efdefba..37f27c0 100644 --- a/due_obd2/due_obd2.ino +++ b/due_obd2/due_obd2.ino @@ -11,9 +11,10 @@ Program to create a car monitor display using: #include #include "obd2_display.h" -// #include "obd2_timer.h" +#include "obd2_timer.h" #define DEBUG 1 +// #define RTT_MR 0x400E1A30U /* pins */ #define PIN_BT_RX 19 @@ -24,6 +25,8 @@ extern uint8_t BigFont[]; extern uint8_t SmallFont[]; char should_clear = 1; +char led_state = LOW; +char flag = 0; /* Set the pins for the display and dev board */ /* Standard Arduino Mega/Due shield : ,38,39,40,41 */ @@ -46,7 +49,16 @@ void setup() { Serial.println("Starting"); #endif - TCCR0A=(1<RTT_MR = RTT_MR_RTTRST | RTT_MR_ALMIEN | RTT_MR_RTPRES(32768/2); + /* set the alarm value to 0*/ + RTT->RTT_AR = 0; + /* enable the interrupt*/ + NVIC_EnableIRQ(RTT_IRQn); +} + +void obd2_timer_reset() +{ + /* To prevent several executions of the interrupt handler, + the interrupt must be disabled in the interrupt handler + and re-enabled when the status register is cleared. + */ + /* disable interrupts */ + RTT->RTT_MR &= ~RTT_MR_ALMIEN; + /* clear the status register */ + RTT->RTT_SR; + /* set the alarm value to 0*/ + RTT->RTT_AR = 0; + /* re-enable the interrupt*/ + RTT->RTT_MR |= RTT_MR_ALMIEN; + /* reset the RTT*/ + RTT->RTT_MR |= RTT_MR_RTTRST; + +} \ No newline at end of file diff --git a/due_obd2/obd2_timer.h b/due_obd2/obd2_timer.h new file mode 100644 index 0000000..495181d --- /dev/null +++ b/due_obd2/obd2_timer.h @@ -0,0 +1,17 @@ +#ifndef OBD2_TIMER_H + +#ifdef __cplusplus + extern "C" { +#endif + +#include "Arduino.h" + +#define CLOCK_FREQ 32768 + +void obd2_timer_init(); +void obd2_timer_reset(); + +#ifdef __cplusplus +} +#endif +#endif // !OBD2_TIMER_H \ No newline at end of file