43 lines
756 B
C
43 lines
756 B
C
#include "uart.h"
|
|
|
|
#include <avr/interrupt.h>
|
|
#include <util/crc16.h>
|
|
|
|
#include "sss7.h"
|
|
|
|
void uart_init(void) {
|
|
UBRRH = UBRR_VAL >> 8; // Setting baudrate
|
|
UBRRL = UBRR_VAL & 0xFF;
|
|
|
|
UCSRB = (1 << TXEN) | (1 << RXEN); // Enable TX and RX
|
|
UCSRC = (1 << URSEL) | (1 << UCSZ1) | (1 << UCSZ0); // Asynchronous 8N1
|
|
|
|
// flush UDR
|
|
do
|
|
{
|
|
UDR;
|
|
}
|
|
while (UCSRA & (1 << RXC));
|
|
|
|
// reset tx and rx complete flags
|
|
UCSRA = (1 << RXEN) | (1 << TXC);
|
|
|
|
UCSRB |= (1 << TXCIE) | (1 << RXCIE); // enable tx and rx interrupts
|
|
}
|
|
|
|
uint8_t uart_get_byte(void) {
|
|
uint8_t byte = UDR;
|
|
return byte;
|
|
}
|
|
|
|
void uart_put_byte(uint8_t byte) {
|
|
UDR = byte;
|
|
}
|
|
ISR(USART_RXC_vect) {
|
|
sss7_process_rx();
|
|
}
|
|
|
|
ISR(USART_TXC_vect) {
|
|
sss7_process_tx();
|
|
}
|