From: Martin Mares Date: Sat, 6 Jul 2019 22:37:55 +0000 (+0200) Subject: Test: Heat exchanger bypass control X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=86c630b3cf02e9899457990b9e44dd0a24d18e60;p=home-hw.git Test: Heat exchanger bypass control --- diff --git a/test-opencm3/test.c b/test-opencm3/test.c index b765805..e49bce7 100644 --- a/test-opencm3/test.c +++ b/test-opencm3/test.c @@ -20,7 +20,17 @@ static void clock_setup(void) static void gpio_setup(void) { + // PC13 = BluePill LED gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13); + gpio_clear(GPIOC, GPIO13); + + // PC14 = bypass LED* + gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO14); + gpio_set(GPIOC, GPIO14); + + // PC15 = bypass opto-coupler + gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO15); + gpio_clear(GPIOC, GPIO15); } static volatile u32 ms_ticks; @@ -51,13 +61,15 @@ static void usart_setup(void) usart_set_baudrate(USART1, 115200); usart_set_databits(USART1, 8); usart_set_stopbits(USART1, USART_STOPBITS_1); - usart_set_mode(USART1, USART_MODE_TX); + usart_set_mode(USART1, USART_MODE_TX_RX); usart_set_parity(USART1, USART_PARITY_NONE); usart_set_flow_control(USART1, USART_FLOWCONTROL_NONE); usart_enable(USART1); } +static bool bypass_active; + static void show_temperature(void) { debug_putc('#'); @@ -69,6 +81,8 @@ static void show_temperature(void) else debug_printf("%3d.%03d", t / 1000, t % 1000); } + debug_putc(' '); + debug_putc('0' + bypass_active); debug_puts("\r\n"); } @@ -86,6 +100,18 @@ int main(void) gpio_toggle(GPIOC, GPIO13); delay_ms(100); ds_step(); + if (usart_get_flag(USART1, USART_SR_RXNE)) { + uint ch = usart_recv(USART1); + if (ch == 'B') { + bypass_active = 1; + gpio_set(GPIOC, GPIO15); // opto-coupler + gpio_clear(GPIOC, GPIO14); // LED + } else if (ch == 'b') { + bypass_active = 0; + gpio_clear(GPIOC, GPIO15); // opto-coupler + gpio_set(GPIOC, GPIO14); // LED + } + } if (cycles++ >= 50) { cycles = 0; show_temperature();