25 lines
577 B
C
25 lines
577 B
C
|
|
#include "uart.h"
|
|
|
|
void init_uart(uint16_t baud) {
|
|
// Configure UART pin directions
|
|
PORTB.DIR &= ~PIN1_bm;
|
|
PORTB.DIR |= PIN0_bm;
|
|
// Set the baudrate
|
|
USART3.BAUD = (uint16_t)USART3_BAUD_RATE(baud);
|
|
// Enable UART TX & RX
|
|
USART3.CTRLB |= USART_TXEN_bm;
|
|
}
|
|
|
|
void USART3_sendChar(char c) {
|
|
// Hold the code while the UART is not ready to send
|
|
while (!(USART3.STATUS & USART_DREIF_bm)) { ; }
|
|
// UART is ready, send the character.
|
|
USART3.TXDATAL = c;
|
|
|
|
}
|
|
|
|
int USART3_printChar(char c, FILE *stream) {
|
|
USART3_sendChar(c);
|
|
return 0;
|
|
} |