I am trying to transmit a byte on the uart of an attiny2313 but the transmit hangs in the loop that waits until UDR is available.
I am using the internal 8MHz clock. Uart configured for 9600baud 8bit 1stopbit
My init code is as following:
#define F_CPU 8000000UL
#define USART_BAUDRATE 9600UL
#define USART_UBBR_VALUE ((F_CPU / (USART_BAUDRATE << 4)) - 1)
UBRRL = (uint8_t)USART_UBBR_VALUE;
UBRRH = (uint8_t)(USART_UBBR_VALUE >> 8);
UCSRB = ((1 << TXEN) | (1<<RXEN));
UCSRC = ((1 << UCSZ1) | (1 << UCSZ0));
After init I enable global interrupts using sei().
Transfer:
while (!(UCSRA & (1<<UDRE)));
UDR = 'B';
It hangs on the while loop, when I remove power from the device, it finally breaks while loop on last moment and sents the B.
I have tried adding delay of 200ms after init but didn't work.
I use similar code for an atmega88 and this is working fine. Anyone an idea why it stays in the while loop?