From 1fdf3f18b7a4cadf0ece2dbeb7d5d8ab479fcf9c Mon Sep 17 00:00:00 2001 From: Xoaquin Castrelo <xoaquin.cb@gmail.com> Date: Sun, 14 Nov 2021 04:38:59 +0000 Subject: [PATCH] Enabled writing to UART. --- emb/uart.cpp | 11 ++++++----- emb/uart.hpp | 7 +++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/emb/uart.cpp b/emb/uart.cpp index 0308b8b..003d682 100644 --- a/emb/uart.cpp +++ b/emb/uart.cpp @@ -12,7 +12,6 @@ void initUart() UCSR0A = (1 << U2X0); // double transmission speed UCSR0B = (1 << RXCIE0) // enable RX complete interrupt - | (1 << UDRIE0) // enable data register empty interrupt | (1 << RXEN0) // enable receiver | (1 << TXEN0); // enable transmitter UCSR0C = (0 << UMSEL01) | (0 << UMSEL00) // asynchronous USART @@ -25,12 +24,14 @@ void initUart() sei(); } -ISR(USART_RX_vect) +void writeUart(uint8_t value) { - uart_add_ch(UDR0); + while (!(UCSR0A & (1 << UDRE0))); + + UDR0 = value; } -ISR(USART_UDRE_vect) +ISR(USART_RX_vect) { - // nothing to do right now + uart_add_ch(UDR0); } diff --git a/emb/uart.hpp b/emb/uart.hpp index 2a10f18..b391efd 100644 --- a/emb/uart.hpp +++ b/emb/uart.hpp @@ -1,9 +1,16 @@ #ifndef UART_H #define UART_H +#include <stdint.h> + /** * Initialises the UART logic. */ void initUart(); +/** + * Writes a character to the UART port. + */ +void writeUart(uint8_t value); + #endif /* UART_H */ -- GitLab