Watchdog and sample interrupt
This commit is contained in:
parent
0990cb8f48
commit
f4f866a347
1 changed files with 30 additions and 0 deletions
30
main.c
30
main.c
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <avr/sleep.h>
|
#include <avr/sleep.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
|
|
||||||
|
@ -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) {
|
int main(void) {
|
||||||
int16_t accel_data[3]; // Array to store accelerometer data (X, Y, Z)
|
int16_t accel_data[3]; // Array to store accelerometer data (X, Y, Z)
|
||||||
int32_t iteration = 0;
|
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();
|
initUART();
|
||||||
|
|
||||||
// Clear the screen
|
// Clear the screen
|
||||||
|
@ -52,6 +79,9 @@ int main(void) {
|
||||||
UART_println("MPU6050 Initialized!");
|
UART_println("MPU6050 Initialized!");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
// Pat the dog
|
||||||
|
wdt_reset();
|
||||||
|
|
||||||
UART_println("%d Hello, World!", iteration++);
|
UART_println("%d Hello, World!", iteration++);
|
||||||
|
|
||||||
// Read accelerometer data
|
// Read accelerometer data
|
||||||
|
|
Loading…
Reference in a new issue