From 24d17688c0433ddf550fe69e851bab473784f357 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sun, 12 Apr 2020 23:59:18 +0200 Subject: [PATCH] Add double speed test and change to atmega328p --- uart/clock.hpp | 2 +- uart/main.cpp | 70 +++++++++++++++++++++++++++++++---------------- uart/type | 2 +- uart/uart | 2 +- uart/uart.cppproj | 17 ++---------- 5 files changed, 52 insertions(+), 41 deletions(-) diff --git a/uart/clock.hpp b/uart/clock.hpp index 977e6d9..052799d 100644 --- a/uart/clock.hpp +++ b/uart/clock.hpp @@ -1,4 +1,4 @@ #pragma once -#define F_CPU 20000000 +#define F_CPU 16'000'000 #include diff --git a/uart/main.cpp b/uart/main.cpp index f694302..aea7316 100644 --- a/uart/main.cpp +++ b/uart/main.cpp @@ -8,44 +8,63 @@ #include "io/io.hpp" #include "uart/uart.hpp" -#define UART1_INT_VECTORS -#include "uart/hardware1.hpp" +#define UART0_INT_VECTORS +#include "uart/hardware0.hpp" + +void doubleSpeedTest() +{ + using namespace uart; + Uart, Driven::INTERRUPT, Mode::ASYNCHRONOUS>> serial; + serial.init(); + + uint8_t counter = 100; + uint8_t data; + + while (counter) { + if (serial.rxByte(data)) { + serial.txByte(data); + --counter; + } + } + + serial.flushTx(); +} void newUartUsage() { using namespace uart; - Uart, Driven::BLOCKING, Mode::ASYNCHRONOUS>> serial1; - serial1.init(); + Uart, Driven::BLOCKING, Mode::ASYNCHRONOUS>> serial; + serial.init(); - serial1 << "New uart hi from RAM. " << F("New uart hi from flash\r\n"); + serial << "New uart hi from RAM. " << F("New uart hi from flash\r\n"); while (false) { uint8_t received = 0; - while (!serial1.peek()) + while (!serial.peek()) ; { - serial1 << F("Peeked: "); - serial1.txByte(received); - serial1 << F("\r\n"); + serial << F("Peeked: "); + serial.txByte(received); + serial << F("\r\n"); } - if (serial1.rxByte(received)) { - serial1 << F("Received: "); - serial1.txByte(received); - serial1 << F("\r\n"); + if (serial.rxByte(received)) { + serial << F("Received: "); + serial.txByte(received); + serial << F("\r\n"); } } - serial1.flushTx(); + serial.flushTx(); } void newUartUsage2() { using namespace uart; - Uart, Driven::INTERRUPT>> serial1; + Uart, Driven::INTERRUPT>> serial1; auto ramString = "Hello World from RAM. "; auto flashString = F("Hello World from flash\r\n"); @@ -61,7 +80,7 @@ void newUartUsage2() void newUartStreamOverloads() { using namespace uart; - Uart, Driven::BLOCKING, Mode::ASYNCHRONOUS>> serial; + Uart, Driven::BLOCKING, Mode::ASYNCHRONOUS>> serial; serial.init(); bool bVal = true; @@ -191,17 +210,18 @@ void spiTest() static inline void initUart(const uint32_t baudRate) { - UBRR1 = static_cast((F_CPU + 8 * baudRate) / (16 * baudRate) - 1); - UCSR1C = (1 << UCSZ11) | (1 << UCSZ10); - UCSR1B = (1 << RXEN1) | (1 << TXEN1); + UBRR0 = static_cast((F_CPU + 8 * baudRate) / (16 * baudRate) - 1); + UCSR0A = 0; + UCSR0C = (1 << UCSZ01) | (1 << UCSZ00); + UCSR0B = (1 << RXEN0) | (1 << TXEN0); } static inline void txUart(uint8_t byte) { - while (!(UCSR1A & (1 << UDRE1))) + while (!(UCSR0A & (1 << UDRE0))) ; - UDR1 = byte; + UDR0 = byte; } static inline void txString(const char *str) @@ -220,11 +240,11 @@ static inline void txString(const detail::FlashString *str) static inline void flushTx() { - while (!(UCSR1A & (1 << UDRE1))) + while (!(UCSR0A & (1 << UDRE0))) ; - while (!(UCSR1A & (1 << TXC1))) + while (!(UCSR0A & (1 << TXC0))) ; - UCSR1A |= (1 << TXC1); + UCSR0A |= (1 << TXC0); } void optimalUartTest() @@ -244,6 +264,8 @@ int main() { sei(); + doubleSpeedTest(); + newUartUsage2(); optimalUartTest(); newUartStreamOverloads(); diff --git a/uart/type b/uart/type index 068a179..ce31ef0 160000 --- a/uart/type +++ b/uart/type @@ -1 +1 @@ -Subproject commit 068a179cef0d1eebe17771270fa82cc3d693c9a5 +Subproject commit ce31ef017f738baaca6f0cbf99dac9d59b5e6811 diff --git a/uart/uart b/uart/uart index 41b9ef7..04b6782 160000 --- a/uart/uart +++ b/uart/uart @@ -1 +1 @@ -Subproject commit 41b9ef74f9138e6eb8559a961d951049db1d7c67 +Subproject commit 04b6782ec457fb22759a097892b863a3ec6eaab4 diff --git a/uart/uart.cppproj b/uart/uart.cppproj index d7c6d98..40dde9b 100644 --- a/uart/uart.cppproj +++ b/uart/uart.cppproj @@ -5,7 +5,7 @@ 7.0 com.Atmel.AVRGCC8.CPP dce6c7e3-ee26-4d79-826b-08594b9ad897 - ATmega1284P + ATmega328P none Executable CPP @@ -30,7 +30,7 @@ com.atmel.avrdbg.tool.atmelice J41800099437 - 0x1E9705 + 0x1E950F @@ -43,20 +43,9 @@ JTAGICE mkII ISP - 5000000 + 125000 - - \Debug\uart.lss - - - .lss - ^\s*(?<address>[a-f0-9]*):\s*.*$ - true - address - $pc - -