From 3953c49f0bb0003f9b1b21bb228f25e4fa45206e Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sat, 26 Jan 2013 18:32:09 +0100 Subject: digital/avr/modules: set uart speed at runtime --- digital/avr/modules/uart/uart.avr.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'digital/avr/modules/uart/uart.avr.c') diff --git a/digital/avr/modules/uart/uart.avr.c b/digital/avr/modules/uart/uart.avr.c index ff735213..c28f2f22 100644 --- a/digital/avr/modules/uart/uart.avr.c +++ b/digital/avr/modules/uart/uart.avr.c @@ -245,9 +245,7 @@ void uart_init (void) { /* Set baud rate. */ -#if (UBRR_VAL >> 8) != 0 UBRRH = UBRR_VAL >> 8; -#endif UBRRL = UBRR_VAL & 0xff; UCSRA = 0; /* Set format and enable uart. */ @@ -263,6 +261,15 @@ uart_init (void) #endif } +/** Change uart speed after init. */ +void +uart_set_speed (uint32_t speed) +{ + uint16_t ubrr_val = AC_FREQ / 16 / speed - 1; + UBRRH = ubrr_val >> 8; + UBRRL = ubrr_val & 0xff; +} + /** Read a char. */ uint8_t uart_getc (void) -- cgit v1.2.3