From 99c2704583d9d5d0f8f8327ee8d188d6e5794488 Mon Sep 17 00:00:00 2001 From: Hauke Petersen Date: Tue, 7 Feb 2017 16:16:45 +0100 Subject: [PATCH] cpu/atmega: implement UART TX only --- cpu/atmega_common/periph/uart.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cpu/atmega_common/periph/uart.c b/cpu/atmega_common/periph/uart.c index 4449ab2bf..1f4ebb30b 100644 --- a/cpu/atmega_common/periph/uart.c +++ b/cpu/atmega_common/periph/uart.c @@ -36,19 +36,20 @@ /** - * @brief Maximum percentage error in calculated baud before switching to double speed transmission (U2X) + * @brief Maximum percentage error in calculated baud before switching to + * double speed transmission (U2X) * * Takes whole numbers from 0 to 100, inclusive, with a default of 2. */ #if defined(UART_BAUD_TOL) -// BAUD_TOL is defined here as it is used by the setbaud.h utility +/* BAUD_TOL is defined here as it is used by the setbaud.h utility */ #define BAUD_TOL UART_BAUD_TOL #else #define BAUD_TOL 2 #endif #if defined(UART_STDIO_BAUDRATE) -// BAUD and F_CPU are required by setbaud.h to calculated BRR +/* BAUD and F_CPU are required by setbaud.h to calculated BRR */ #define BAUD UART_STDIO_BAUDRATE #define F_CPU CLOCK_CORECLOCK #include @@ -129,8 +130,15 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg) dev[uart]->CSRC = (1 << UCSZ00) | (1 << UCSZ01); /* set clock divider */ _set_brr(uart, baudrate); + /* enable RX and TX and the RX interrupt */ - dev[uart]->CSRB = ((1 << RXCIE0) | (1 << RXEN0) | (1 << TXEN0)); + if (rx_cb) { + dev[uart]->CSRB = ((1 << RXCIE0) | (1 << RXEN0) | (1 << TXEN0)); + } + else { + dev[uart]->CSRB = (1 << TXEN0); + } + return UART_OK; }