detect no battery
This commit is contained in:
parent
281c9924f6
commit
ec57456537
19
main.c
19
main.c
@ -312,13 +312,13 @@ static void clock_hours(void)
|
||||
*/
|
||||
static void process_command(char* str)
|
||||
{
|
||||
/* split command */
|
||||
// split command
|
||||
const char* delimiter = " ";
|
||||
char* word = strtok(str,delimiter);
|
||||
if (!word) {
|
||||
goto error;
|
||||
}
|
||||
/* parse command */
|
||||
// parse command
|
||||
if (0==strcmp(word,"help")) {
|
||||
printf("available commands:\n");
|
||||
printf("time [HH:MM:SS]\n");
|
||||
@ -348,7 +348,7 @@ int main(void)
|
||||
{
|
||||
rcc_clock_setup_in_hse_8mhz_out_72mhz(); // use 8 MHz high speed external clock to generate 72 MHz internal clock
|
||||
usart_setup(); // setup USART (for printing)
|
||||
cdcacm_setup(); // setup USB CDC ACM (for printing)
|
||||
cdcacm_setup(); // setup USB CDC ACM (for printing)
|
||||
setbuf(stdout, NULL); // set standard out buffer to NULL to immediately print
|
||||
setbuf(stderr, NULL); // set standard error buffer to NULL to immediately print
|
||||
|
||||
@ -406,7 +406,7 @@ int main(void)
|
||||
|
||||
printf("welcome to the CuVoodoo LED clock\n"); // print welcome message
|
||||
led_on(); // switch on LED to indicate setup completed
|
||||
|
||||
|
||||
// read internal reference 1.2V and RTC battery voltages
|
||||
uint8_t channels[] = {ADC_CHANNEL17, BATTERY_ADC_CHANNEL}; // voltages to convert
|
||||
adc_set_regular_sequence(ADC1, LENGTH(channels), channels); // set channels to convert
|
||||
@ -417,10 +417,14 @@ int main(void)
|
||||
while (!adc_eoc(ADC1)); // wait until conversion finished
|
||||
uint16_t battery_value = adc_read_regular(ADC1); // read converted battery voltage
|
||||
float battery_voltage = battery_value*1.2/ref_value; // calculate battery voltage
|
||||
if (battery_voltage<2.4) {
|
||||
printf("/!\\ low ");
|
||||
if (battery_voltage<1.0) {
|
||||
printf("no battery detected\n");
|
||||
} else {
|
||||
if (battery_voltage<2.4) {
|
||||
printf("/!\\ low ");
|
||||
}
|
||||
printf("battery voltage: %.2fV\n", battery_voltage);
|
||||
}
|
||||
printf("battery voltage: %.2fV\n", battery_voltage);
|
||||
|
||||
// show voltage on LEDs
|
||||
if (battery_voltage<1.0) { // battery probable not connected
|
||||
@ -500,6 +504,7 @@ int main(void)
|
||||
adc_start_conversion_regular(ADC1); // start measuring ambient luminosity
|
||||
}
|
||||
if ((rtc_get_counter_val()%ticks_second)==0) { // one second passed
|
||||
printf("tick: %lu\n", rtc_get_counter_val());
|
||||
led_toggle(); // LED activity to show we are not stuck
|
||||
}
|
||||
if ((rtc_get_counter_val()%ticks_minute)==0) { // one minute passed
|
||||
|
Loading…
Reference in New Issue
Block a user