diff --git a/main.c b/main.c index 1c4e233..fc213ae 100644 --- a/main.c +++ b/main.c @@ -9,6 +9,8 @@ #include #include +#include +#include #include #include @@ -33,10 +35,35 @@ void blink() { } } +ISR(TIMER1_COMPA_vect) { + UART_println("Interrupt detected!"); + + // Clear the interrupt flag + TIFR1 |= (1 << TOV1); +} + +// We will use Timer1 for the interrupt +void configure_interrupt() { + TCNT1 = 0; // Initialize the counter value to 0 + TCCR1A = 0; // Set the timer to normal mode + TCCR1B = 0; // Set the timer to normal mode + OCR1A = 31250; // 31250 for a 2 second delay, 15624 for a 1 second delay + TCCR1B |= (1 << WGM12); // Set the timer to CTC mode + TCCR1B |= (1 << CS02) | (1 << CS00); // Set the prescaler to 1024 + TIMSK1 |= (1 << OCIE1A); // Enable overflow interrupt + sei(); // Enable global interrupts (cli() to disable) +} + int main(void) { int16_t accel_data[3]; // Array to store accelerometer data (X, Y, Z) int32_t iteration = 0; + // Set the watchdog timer to 8 seconds + wdt_enable(WDTO_8S); + + // Set the sleep mode to idle + set_sleep_mode(SLEEP_MODE_IDLE); + initUART(); // Clear the screen @@ -52,6 +79,9 @@ int main(void) { UART_println("MPU6050 Initialized!"); while (1) { + // Pat the dog + wdt_reset(); + UART_println("%d Hello, World!", iteration++); // Read accelerometer data