# HG changeset patch # User Matt Johnston # Date 1337339740 -28800 # Node ID 52cb08a01171e9088fb1b5dc86ea1e25eaae79d0 # Parent 9d538f674ff0b55a84c207db3d5e073c9a7d4392 serial prints something diff -r 9d538f674ff0 -r 52cb08a01171 Makefile --- a/Makefile Mon May 14 00:22:57 2012 +0800 +++ b/Makefile Fri May 18 19:15:40 2012 +0800 @@ -17,10 +17,12 @@ # default_serial = "avrdoper" # FUSES ........ Parameters for avrdude to flash the fuses appropriately. -DEVICE = atmega168 +DEVICE = atmega328 +PROGDEVICE = atmega328p CLOCK = 1000000 PROGRAMMER = #-c stk500v2 -P avrdoper -OBJECTS = main.o ff.o mmc.o onewire.o +PROGRAMMER = -c stk500 -P ~/dev/stk500 -p $(PROGDEVICE) +OBJECTS = main.o #ff.o mmc.o onewire.o LIBS = -lm FUSES = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m @@ -49,7 +51,7 @@ # Tune the lines below only if you know what you are doing: -AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE) +AVRDUDE = avrdude $(PROGRAMMER) COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -g -std=c99 -mcall-prologues # symbolic targets: diff -r 9d538f674ff0 -r 52cb08a01171 main.c --- a/main.c Mon May 14 00:22:57 2012 +0800 +++ b/main.c Fri May 18 19:15:40 2012 +0800 @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -27,7 +28,11 @@ #define COMMS_WAKE 3600 #define BAUD 9600 -#define UBRR ((F_CPU)/16/(BAUD)-1) +#define UBRR ((F_CPU)/8/(BAUD)-1) + +#define PORT_LED PORTC +#define DDR_LED DDRC +#define PIN_LED PC4 #define NUM_MEASUREMENTS 300 @@ -35,36 +40,58 @@ static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE); -static uint8_t n_measurements; +static uint8_t n_measurements = 0; // stored as 1/5 degree above 0 static uint8_t measurements[NUM_MEASUREMENTS]; static uint8_t internal_measurements[NUM_MEASUREMENTS]; // boolean flags -static uint8_t need_measurement; -static uint8_t need_comms; -static uint8_t comms_done; +static uint8_t need_measurement = 0; +static uint8_t need_comms = 0; +static uint8_t comms_done = 0; -static uint8_t readpos; +static uint8_t readpos = 0; static char readbuf[30]; -static uint8_t measure_count; -static uint16_t comms_count; +static uint8_t measure_count = 0; +static uint16_t comms_count = 0; static void deep_sleep(); static void -uart_on(unsigned int ubrr) +uart_on() { // baud rate - UBRR0H = (unsigned char)(ubrr >> 8); - UBRR0L = (unsigned char)ubrr; + UBRR0H = (unsigned char)(UBRR >> 8); + UBRR0L = (unsigned char)UBRR; + // set 2x clock, improves accuracy of UBRR + UCSR0A |= _BV(U2X0); UCSR0B = _BV(RXCIE0) | _BV(RXEN0) | _BV(TXEN0); //8N1 - UCSR0C = _BV(UMSEL00) | _BV(UCSZ00); + UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); // Power reduction register - PRR &= ~_BV(PRUSART0); + //PRR &= ~_BV(PRUSART0); +} + +static void +uart_test() +{ + + UDR0 = 'n'; + _delay_ms(50); + UDR0 = 'f'; + _delay_ms(50); + while ( !( UCSR0A & (1<