From 40213592300e230305ae564dfc931cb224a1f580 Mon Sep 17 00:00:00 2001 From: _N0x Date: Sat, 4 Dec 2021 23:11:51 +0100 Subject: [PATCH] Fixed issues with UART and added proper interupts --- EmbeddedSystemsTHM/UART.c | 188 ++++++++++++++++++++++---------------- EmbeddedSystemsTHM/UART.h | 22 ++--- 2 files changed, 118 insertions(+), 92 deletions(-) diff --git a/EmbeddedSystemsTHM/UART.c b/EmbeddedSystemsTHM/UART.c index b897129..bf22af6 100644 --- a/EmbeddedSystemsTHM/UART.c +++ b/EmbeddedSystemsTHM/UART.c @@ -1,106 +1,132 @@ /* * UART.c * - * Created: 18/11/2021 17:13:25 + * Created: 25/11/2021 16:26:10 * Author: n0x */ -#include -#include -#include #include "UART.h" -volatile int enabled = 1; +#define SIZE_BUFFER 500 +struct CircularBuffer{ + volatile char data[SIZE_BUFFER]; + volatile uint16_t Readpointer; + volatile uint16_t Writepointer; +}; + +struct CircularBuffer TxBuffer; +struct CircularBuffer RxBuffer; +volatile uint8_t TxActive; -/* Schreiben Sie eine Funktion, welche die UART Schnittstelle für das Senden von - Daten mit - 9600Baud, - 8 Bit, - keine Parität und - 1 Stopbit - initialisiert. */ void uart_init(void) { - /* set BAUD rate to 9600 */ - UBRR0 = 103; - - /* Async UART */ - UCSR0C |= (0<=SIZE_BUFFER){ + TxBuffer.Writepointer = 0; + } + } else { + TxActive = 1; + UDR0 = c; + } + UCSR0B |= (1<= SIZE_BUFFER){ + TxBuffer.Readpointer = 0; + } + } else { + TxActive = 0; + } +} + +/* ------------------------ */ +/* Receiving Data */ +/* ------------------------ */ + +uint8_t +uart_data_available(void) +{ + uint8_t dataAvailabel = 0; + UCSR0B &= ~(1<= SIZE_BUFFER){ + RxBuffer.Readpointer = 0; + } + } + UCSR0B |= (1<>FE0))) == 0){ + RxBuffer.data[RxBuffer.Writepointer++] = data; + if(RxBuffer.Writepointer >= SIZE_BUFFER) { + RxBuffer.Writepointer = 0; + } + } } \ No newline at end of file diff --git a/EmbeddedSystemsTHM/UART.h b/EmbeddedSystemsTHM/UART.h index 3483cfb..195815d 100644 --- a/EmbeddedSystemsTHM/UART.h +++ b/EmbeddedSystemsTHM/UART.h @@ -1,21 +1,21 @@ /* - * UART.h + * UART2.h * - * Created: 18/11/2021 17:13:16 + * Created: 25/11/2021 16:25:59 * Author: n0x */ +#include +#include -#ifndef UART_H_ -#define UART_H_ +#ifndef UART2_H_ +#define UART2_H_ void uart_init(void); -void uart_send(char* string); +void uart_send_byte(char c); +void uart_send_string(char* string); +uint8_t uart_data_available(void); +char uart_get_data(void); -void uart_init_isr(void); -void uart_send_isr(char* string); - -int checkIfBlocked(void); - -#endif /* UART_H_ */ \ No newline at end of file +#endif /* UART2_H_ */ \ No newline at end of file