diff --git a/emb/uart.cpp b/emb/uart.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0308b8b1a6817e3af5c32a47a968a8ff373893b0 --- /dev/null +++ b/emb/uart.cpp @@ -0,0 +1,36 @@ +#include "uart.hpp" + +#include "servos.hpp" +#include "command.h" + +#include <avr/io.h> +#include <avr/interrupt.h> + +void initUart() +{ + cli(); + + 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 + | (0 << UPM01) | (0 << UPM00) // no parity bit + | (0 << USBS0) // 1 stop bit + | (1 << UCSZ01) | (1 << UCSZ00); // 8 data bits + + UBRR0 = 16; // 115.2k baud rate + + sei(); +} + +ISR(USART_RX_vect) +{ + uart_add_ch(UDR0); +} + +ISR(USART_UDRE_vect) +{ + // nothing to do right now +} diff --git a/emb/uart.hpp b/emb/uart.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2a10f18db8adc083d80ede632b613e43860e8635 --- /dev/null +++ b/emb/uart.hpp @@ -0,0 +1,9 @@ +#ifndef UART_H +#define UART_H + +/** + * Initialises the UART logic. + */ +void initUart(); + +#endif /* UART_H */