X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/208edeee0f97a56697f0b15b519a9e723436f007..03ee87b35abdb8b92e8b55ec040fa943f9a6786c:/Projects/TemperatureDataLogger/TempDataLogger.c diff --git a/Projects/TemperatureDataLogger/TempDataLogger.c b/Projects/TemperatureDataLogger/TempDataLogger.c index 6cb1792a4..b181ec2f8 100644 --- a/Projects/TemperatureDataLogger/TempDataLogger.c +++ b/Projects/TemperatureDataLogger/TempDataLogger.c @@ -1,13 +1,13 @@ /* LUFA Library - Copyright (C) Dean Camera, 2009. + Copyright (C) Dean Camera, 2010. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ /* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted @@ -64,7 +64,7 @@ FATFS DiskFATState; /** FAT Fs structure to hold a FAT file handle for the log data write destination. */ FIL TempLogFile; -/** Counter to count the number of 10 millisecond tick that has elapsed since the last sample */ +/** Counter to count the number of 10 millisecond ticks that has elapsed since the last sample */ uint16_t CurrentLogTick; @@ -73,6 +73,10 @@ ISR(TIMER1_COMPA_vect, ISR_BLOCK) if (CurrentLogTick++ != LOG_INTERVAL_10MS) return; + uint8_t LEDMask = LEDs_GetLEDs(); + + LEDs_SetAllLEDs(LEDMASK_USB_BUSY); + CurrentLogTick = 0; if (USB_DeviceState == DEVICE_STATE_Unattached) @@ -80,6 +84,8 @@ ISR(TIMER1_COMPA_vect, ISR_BLOCK) f_printf(&TempLogFile, "%d Degrees\r\n", Temperature_GetTemperature()); f_sync(&TempLogFile); } + + LEDs_SetAllLEDs(LEDMask); } @@ -96,11 +102,12 @@ int main(void) f_mount(0, &DiskFATState); f_open(&TempLogFile, LOG_FILENAME, FA_OPEN_ALWAYS | FA_WRITE); f_lseek(&TempLogFile, TempLogFile.fsize); - - /* Write out the log seperator line */ f_printf(&TempLogFile, "===========================\r\n"); - Temperature_GetTemperature(); // Discard first temperature reading to ensure accuracy - + + /* Discard the first sample from the temperature sensor, as it is generally incorrect */ + uint8_t Dummy = Temperature_GetTemperature(); + (void)Dummy; + for (;;) { MS_Device_USBTask(&Disk_MS_Interface); @@ -121,15 +128,14 @@ void SetupHardware(void) /* Hardware Initialization */ LEDs_Init(); SPI_Init(SPI_SPEED_FCPU_DIV_2 | SPI_SCK_LEAD_FALLING | SPI_SAMPLE_TRAILING | SPI_MODE_MASTER); - Dataflash_Init(); - USB_Init(); ADC_Init(ADC_REFERENCE_AVCC | ADC_FREE_RUNNING | ADC_PRESCALE_128); Temperature_Init(); + Dataflash_Init(); + USB_Init(); /* 10ms interval timer configuration */ OCR1A = (((F_CPU / 1024) / 100) - 1); - TCCR1A = (1 << WGM01); // CTC mode - TCCR1B = (1 << CS12) | (1 << CS10); // Fcpu/1024 speed + TCCR1B = (1 << WGM12) | (1 << CS12) | (1 << CS10); // CTC mode, Fcpu/1024 speed TIMSK1 = (1 << OCIE1A); /* Clear Dataflash sector protections, if enabled */ @@ -154,6 +160,7 @@ void EVENT_USB_Device_Disconnect(void) f_mount(0, &DiskFATState); f_open(&TempLogFile, LOG_FILENAME, FA_OPEN_ALWAYS | FA_WRITE); f_lseek(&TempLogFile, TempLogFile.fsize); + f_printf(&TempLogFile, "===========================\r\n"); } /** Event handler for the library USB Configuration Changed event. */