From 49939141cc4fcf4736a55de855416c5ddfc661ea Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Thu, 4 Jul 2019 14:45:47 +0200 Subject: [PATCH] Test: Experimental air temperature readings --- test-opencm3/ds18b20.c | 5 +++-- test-opencm3/test.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/test-opencm3/ds18b20.c b/test-opencm3/ds18b20.c index 53df2a6..434af43 100644 --- a/test-opencm3/ds18b20.c +++ b/test-opencm3/ds18b20.c @@ -18,7 +18,7 @@ static volatile u32 ds_dma_buffer; #define DS_DMA DMA1 #define DS_DMA_CH 6 -#define DS_DEBUG +#undef DS_DEBUG #undef DS_DEBUG2 #ifdef DS_DEBUG @@ -379,8 +379,9 @@ void ds_step(void) if (!maxn--) return; ds_current_id++; - if (ds_current_id >= DS_NUM_SENSORS) + if (ds_current_id >= DS_NUM_SENSORS) { ds_current_id = 0; + } } while (!ds_sensors[ds_current_id].address[0]); #endif if (!ds_activate()) { diff --git a/test-opencm3/test.c b/test-opencm3/test.c index 309fc75..b765805 100644 --- a/test-opencm3/test.c +++ b/test-opencm3/test.c @@ -58,6 +58,20 @@ static void usart_setup(void) usart_enable(USART1); } +static void show_temperature(void) +{ + debug_putc('#'); + for (uint i=0; ds_sensors[i].address[0]; i++) { + debug_putc(' '); + int t = ds_sensors[i].current_temp; + if (t == DS_TEMP_UNKNOWN) + debug_puts("---.---"); + else + debug_printf("%3d.%03d", t / 1000, t % 1000); + } + debug_puts("\r\n"); +} + int main(void) { clock_setup(); @@ -66,10 +80,16 @@ int main(void) usart_setup(); ds_init(); + + byte cycles = 0; for (;;) { gpio_toggle(GPIOC, GPIO13); delay_ms(100); ds_step(); + if (cycles++ >= 50) { + cycles = 0; + show_temperature(); + } } return 0; -- 2.39.2