I'm trying enable serial transmission (UART Tx) on my AVR atmega328p embedded on an Uno board. I'm trying to do all this without any of Arduino libraries except its register header file.
Here is my code taken almost directly from the datasheet USART example:
#define F_CPU 16000000L #include <util/delay.h> #include "header/registers.h" // Just a list of registers mapped to memory. #define BAUD 9600 #define MYUBRR (F_CPU / 8 / BAUD-1)/2 void USART_Init(unsigned int ubrr){ /*Set baud rate */ UBRR0H = (unsigned char)(ubrr>>8); UBRR0L = (unsigned char)ubrr; /*Enable receiver and transmitter */ UCSR0B = (1<<RXEN0)|(1<<TXEN0); /* Set frame format: 8data, 2stop bit */ UCSR0C = (1<<USBS0)|(3<<UCSZ00); } void USART_Transmit(unsigned char data){ /* Wait for empty transmit buffer */ while (!(UCSR0A & (1<<UDRE0))); /* Put data into buffer, sends the data */ UDR0 = data; } int main(void){ USART_Init(MYUBRR); while (1){ USART_Transmit(0x1); _delay_ms(1000); // wait 1 second. } return 0; }
The builtin `Tx` LED on the Uno board is flashing as expected every second BUT a connected LED to the Tx port on Uno is still constantly high.
Is the `Tx` port on Uno not directly attached to the chip?