Mercurial > templog
changeset 316:8f32eb67a279
reading DS18B20 works
add some linker optimisations
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 19 May 2012 17:10:13 +0800 |
parents | 7d409dded901 |
children | 4ef5ce596ec6 |
files | Makefile crc8.o main.c |
diffstat | 3 files changed, 28 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Fri May 18 23:57:08 2012 +0800 +++ b/Makefile Sat May 19 17:10:13 2012 +0800 @@ -21,8 +21,8 @@ PROGDEVICE = atmega328p CLOCK = 2000000 PROGRAMMER = #-c stk500v2 -P avrdoper -PROGRAMMER = -c stk500 -P ~/dev/stk500 -p $(PROGDEVICE) -OBJS_1WIRE = onewire.o ds18x20.o uart_addon.o crc8.o +PROGRAMMER = -c stk500 -P ~/dev/stk500 -p $(PROGDEVICE) -B 2 +OBJS_1WIRE = onewire.o ds18x20.o uart_addon.o crc8.o uart.o OBJS_SD = ff.o mmc.o OBJECTS = main.o OBJECTS += $(OBJS_1WIRE) @@ -58,7 +58,7 @@ # Tune the lines below only if you know what you are doing: AVRDUDE = avrdude $(PROGRAMMER) -COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -g -std=c99 -mcall-prologues +COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -g -std=c99 -mcall-prologues -fdata-sections -ffunction-sections -Wl,--print-gc-sections -Wl,--gc-sections -Wl,--relax # symbolic targets: all: main.hex
--- a/main.c Fri May 18 23:57:08 2012 +0800 +++ b/main.c Sat May 19 17:10:13 2012 +0800 @@ -15,6 +15,7 @@ #include "integer.h" #include "onewire.h" +#include "ds18x20.h" // configuration params // - measurement interval @@ -28,7 +29,7 @@ #define COMMS_WAKE 3600 -#define BAUD 9600 +#define BAUD 19200 #define UBRR ((F_CPU)/8/(BAUD)-1) #define PORT_LED PORTC @@ -37,7 +38,7 @@ #define NUM_MEASUREMENTS 300 -static int uart_putchar(char c, FILE *stream); +int uart_putchar(char c, FILE *stream); static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL, _FDEV_SETUP_WRITE); @@ -87,16 +88,22 @@ //PRR |= _BV(PRUSART0); } -static int +int uart_putchar(char c, FILE *stream) { + // XXX should sleep in the loop for power. if (c == '\n') { - uart_putchar('\r', stream); + loop_until_bit_is_set(UCSR0A, UDRE0); + UDR0 = '\r';; } - // XXX should sleep in the loop for power. loop_until_bit_is_set(UCSR0A, UDRE0); UDR0 = c; + if (c == '\r') + { + loop_until_bit_is_set(UCSR0A, UDRE0); + UDR0 = '\n';; + } return 0; } @@ -153,7 +160,6 @@ ISR(USART_RX_vect) { char c = UDR0; - printf_P(PSTR("wake up '%c'\n"), c); if (c == '\n') { readbuf[readpos] = '\0'; @@ -173,7 +179,6 @@ ISR(TIMER2_COMPA_vect) { - DEBUG("wake up\n"); measure_count ++; comms_count ++; if (measure_count == MEASURE_WAKE) @@ -197,15 +202,11 @@ static void deep_sleep() { - DEBUG("deep sleep\n"); // p119 of manual OCR2A = SLEEP_COMPARE; loop_until_bit_is_clear(ASSR, OCR2AUB); - DEBUG("really about to\n"); - set_sleep_mode(SLEEP_MODE_PWR_SAVE); - DEBUG("done.\n"); sleep_mode(); } @@ -346,7 +347,12 @@ static void test1wire() { - ow_reset(); + //ow_reset(); + + uint8_t ret = DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL); + printf("ret %d\n", ret); + _delay_ms(DS18B20_TCONV_12BIT); + DS18X20_read_meas_all_verbose(); } int main(void) @@ -368,10 +374,13 @@ // for testing uart_on(); - DEBUG("power off\n"); - sei(); - DEBUG("sei done\n"); + //sei(); + for (;;) + { + test1wire(); + long_delay(2000); + } // set up counter2. // COM21 COM20 Set OC2 on Compare Match (p116) @@ -384,8 +393,6 @@ // interrupt TIMSK2 = _BV(OCIE2A); - DEBUG("async setup\n"); - #ifdef TEST_MODE for (;;) { @@ -411,6 +418,7 @@ deep_sleep(); blink(); + printf("."); } #endif return 0; /* never reached */