From 00468a3f53b6624bc99248189467032c7a380a38 Mon Sep 17 00:00:00 2001 From: Ian Martin Date: Wed, 22 Jan 2014 18:41:55 -0500 Subject: [PATCH] Fix buggy UART baudrate calculation in the RL78 UART driver. --- cpu/rl78/uart0.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cpu/rl78/uart0.c b/cpu/rl78/uart0.c index 6fa1e28a2..e40efc2c6 100644 --- a/cpu/rl78/uart0.c +++ b/cpu/rl78/uart0.c @@ -39,13 +39,12 @@ #include "uart0.h" #define DESIRED_BAUDRATE 9600 -#define FUDGE_FACTOR 4 -/* Note that only 9600 and 115200 bps were tested: */ -#define PRESCALE_THRESH ((9600 + 115200) / 2) +/* Note that only 9600, 38400, and 115200 bps were tested. */ +#define PRESCALE_THRESH ((38400 + 115200) / 2) #define PRS_VALUE ((DESIRED_BAUDRATE < PRESCALE_THRESH) ? 4 : 0) -#define f_MCK (f_CLK / (1 << PRS_VALUE) / FUDGE_FACTOR) -#define SDR_VALUE ((f_MCK / DESIRED_BAUDRATE) >> 1) +#define f_MCK (f_CLK / (1 << PRS_VALUE)) +#define SDR_VALUE (f_MCK / DESIRED_BAUDRATE / 2 - 1) void uart0_init(void)