From 60608dcaa522d405800b8a49e2896580f5b80ceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Sat, 30 Apr 2016 12:11:54 +0200 Subject: [PATCH] use RTC --- main.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 099bf13..c92e8db 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,6 @@ #include // Cortex M3 utilities #include // interrupt utilities #include // external interrupt utilities -#include // timer utilities #include // ADC utilities #include // real time clock utilities @@ -43,6 +42,7 @@ #include "usart.h" // USART utilities #include "usb_cdcacm.h" // USB CDC ACM utilities #include "led_ws2812b.h" // WS2812b LEDs utilities +#include "rtc_ds1307.h" // Real Time Clock DS1307 utilities /** @defgroup main_flags flag set in interrupts to be processed in main task * @{ @@ -80,10 +80,10 @@ const uint32_t ticks_midday = 12*60*60*TICKS_PER_SECOND; /** @defgroup photoresistor_adc ADC used to ambient luminosity * @{ */ -#define PHOTORESISTOR_ADC_CHANNEL ADC_CHANNEL0 /**< ADC channel */ +#define PHOTORESISTOR_ADC_CHANNEL ADC_CHANNEL1 /**< ADC channel */ #define PHOTORESISTOR_PORT GPIOA /**< port on which the battery is connected */ #define PHOTORESISTOR_PORT_RCC RCC_GPIOA /**< timer port peripheral clock */ -#define PHOTORESISTOR_PIN GPIO0 /**< pin of the port on which the battery is connected */ +#define PHOTORESISTOR_PIN GPIO1 /**< pin of the port on which the battery is connected */ /** @} */ @@ -377,11 +377,14 @@ int main(void) nvic_enable_irq(BUTTON_IRQ); // enable interrupt #endif - // setup RTC + // setup internal RTC rtc_auto_awake(RCC_LSE, 32768/ticks_second-1); // ensure RTC is on, uses the 32.678 kHz LSE, and the prescale is set to our tick speed, else update backup registers accordingly (power off the micro-controller for the change to take effect) rtc_interrupt_enable(RTC_SEC); // enable RTC interrupt on "seconds" nvic_enable_irq(NVIC_RTC_IRQ); // allow the RTC to interrupt + // setup external RTC + rtc_setup(); // setup RTC module + // generate gamma correction table (with fixed gamma value) for (uint16_t i=0; i