diff --git a/uart/main.cpp b/uart/main.cpp index 302aea0..bfbc275 100644 --- a/uart/main.cpp +++ b/uart/main.cpp @@ -11,13 +11,12 @@ void newUartUsage() { using namespace uart; - Uart, Driven::INTERRUPT>> serial1; + Uart, Driven::INTERRUPT>> serial1; serial1.init(); - sei(); - serial1 << F("Hello World from RAM. ") << F("Hello World from flash\r\n"); + serial1 << "New uart hi from RAM. " << F("New uart hi from flash\r\n"); - while (true) { + while (false) { uint8_t received = 0; while (!serial1.peek()) @@ -36,15 +35,15 @@ void newUartUsage() } } - _delay_ms(1000); + serial1.flushTx(); } void newUartUsage2() { using namespace uart; - using config = Config<9600, DataBits::EIGHT, Parity::NONE, StopBits::ONE>; - using uart0 = Hardware0; + using config = Config<115200, DataBits::EIGHT, Parity::NONE, StopBits::ONE>; + using uart0 = Hardware0; Uart serial; serial.init(); @@ -57,9 +56,8 @@ void newUartUsage2() void newUartStreamOverloads() { using namespace uart; - Uart1> serial; + Uart, Driven::BLOCKING>> serial; serial.init(); - sei(); bool bVal = true; char chVal = 'c'; @@ -108,7 +106,7 @@ void newUartStreamOverloads() serial.txNumber(number); serial << F("\r\n"); - _delay_ms(1000); + serial.flushTx(); } /* @@ -189,7 +187,7 @@ void spiTest() */ static inline void initUart(const uint32_t baudRate) { - UBRR1 = static_cast((F_CPU / (16 * baudRate)) - 1); + UBRR1 = static_cast((F_CPU + 8 * baudRate) / (16 * baudRate) - 1); UCSR1C = (1 << UCSZ11) | (1 << UCSZ10); UCSR1B = (1 << RXEN1) | (1 << TXEN1); } @@ -216,24 +214,37 @@ static inline void txString(const detail::FlashString *str) txUart(ch); } +static inline void flushTx() +{ + while (!(UCSR1A & (1 << UDRE1))) + ; + while (!(UCSR1A & (1 << TXC1))) + ; + UCSR1A |= (1 << TXC1); +} + void optimalUartTest() { auto ramString = "Hello World from RAM. "; auto flashString = F("Hello World from flash\r\n"); - initUart(9600); + initUart(115200); txString(ramString); txString(flashString); - _delay_ms(1000); + flushTx(); } int main() { - // newUartUsage(); + sei(); + newUartUsage(); + optimalUartTest(); newUartStreamOverloads(); - // optimalUartTest(); + + txString(F("\r\n")); + flushTx(); // spiTest(); diff --git a/uart/uart b/uart/uart index b6c1c3b..8153696 160000 --- a/uart/uart +++ b/uart/uart @@ -1 +1 @@ -Subproject commit b6c1c3b51b44b3d7cb32e7f5f0222ecc155f8294 +Subproject commit 8153696309a72ee551a37b17e4eb8ddcda62d0de