# HG changeset patch # User kripperger@CL-SEC241-09.cedarville.edu # Date 2012-11-19 17:22:18 # Node ID ebc4074e751f75f247634cf5f83baae5066b1ead # Parent ccde21039881346e400b65b9c9de59db4a4b0a10 Timer setup diff --git a/slave/slave/lib/spi.h b/slave/slave/lib/spi.h --- a/slave/slave/lib/spi.h +++ b/slave/slave/lib/spi.h @@ -13,7 +13,7 @@ #include -#define SPI_SS_PIN PORTB4 //DEBUG //THIS IS WRONG FOR NOW... +#define SPI_SS_PIN PORTA1 //DEBUG #define SPI_SCK_PIN PORTB7 #define SPI_MOSI_PIN PORTB5 #define SPI_MISO_PIN PORTB6 diff --git a/slave/slave/modules.c b/slave/slave/modules.c --- a/slave/slave/modules.c +++ b/slave/slave/modules.c @@ -7,6 +7,8 @@ #include #include + #include "config.h" + #include #include "modules.h" @@ -80,6 +82,12 @@ void modules_geiger_setup() { + ASSR = 0x20; //enable timer2 async mode with an external crystal + _delay_ms(250); //let external 32KHz crystal stabilize + TCCR2B = 0x05; //set the prescaler to 128: 32.768kHz / 128 = 1Hz overflow + TIFR2 = 0x1; //reset timer2 overflow interrupt flag + TIMSK2 = 0x01; //enable interrupt on overflow + } diff --git a/slave/slave/slave.c b/slave/slave/slave.c --- a/slave/slave/slave.c +++ b/slave/slave/slave.c @@ -15,9 +15,8 @@ #include #include +#include #include -#include - #include "modules.h" //#include "lib/serial.h" //Not made yet #include "lib/led.h" @@ -28,12 +27,22 @@ void micro_setup() { // Generic microcontroller config options - - DDRA=0xFF; //PORTA is output //DEBUG - - + DDRA = 0xFF; //PORTA is output //DEBUG + + + + + } +ISR(TIMER2_OVF_vect) //Timer 2 overflow interrupt handler +{ + // This executes every second. Update real-time clocks + // Used only in Geiger module + + + TIFR2 = 0x1; // Reset timer2 overflow interrupt flag +} int main(void) @@ -52,7 +61,8 @@ int main(void) uint8_t temp; //DEBUG - + PORTA=0;//DEBUG + temp=0;//DEBUG while(1) { @@ -72,10 +82,10 @@ int main(void) //i2c_write(RTC_ADDR, 0x05, 0x3A); //DEBUG: EXAMPLE - _delay_ms(10); - temp = i2c_read(RTC_ADDR, 0x02); //DEBUG: EXAMPLE: seconds + //_delay_ms(10); + //temp = i2c_read(RTC_ADDR, 0x02); //DEBUG: EXAMPLE: seconds - PORTA = temp; //DEBUG + // PORTA = temp; //DEBUG diff --git a/slave/slave/slave.cproj b/slave/slave/slave.cproj --- a/slave/slave/slave.cproj +++ b/slave/slave/slave.cproj @@ -151,5 +151,10 @@ + + + compile + + \ No newline at end of file