/* * Debugger_Demo.c * */ #include #include #include #define F_CPU 3333333UL #define BAUD_9600 ((4UL*F_CPU)/9600) int uart_transmit(char data, FILE* stream){ while (!(USART0.STATUS & (1 << USART_DREIF_bp))){ //Wait for ongoing transmission to finish (if there is one) } USART0.TXDATAL = data; //Put new data in register return 0; } void uart_init(unsigned long baud){ PORTB.OUTSET |= (1 << PIN2_bp); PORTB.DIRSET |= (1 << PIN2_bp); USART0.BAUD = baud; //Set baudrate USART0.CTRLB |= (1 << USART_RXEN_bp) | (1 << USART_TXEN_bp); //Enable RX and TX USART0.CTRLA |= (1 << USART_RXCIE_bp); //Enable interupts on RX fdevopen(uart_transmit, NULL); //Allows the use of printf() } ISR(USART0_RXC_vect){ uint8_t data = USART0.RXDATAL; //We must read the data to clear the interrupt flag } int main(void) { uart_init(BAUD_9600); while (1) { } }