I'm trying to use the UART0 on a Mega162 but I'm having problems setting UCSR0C. Here is my UART initialization function:
void uart_init(void) { uint8_t tmp; rx_buf_head = 0; rx_buf_tail = 0; tx_buf_head = 0; tx_buf_tail = 0; tmp = SREG; cli(); UBRR0H = UBRRH_VALUE; UBRR0L = UBRRL_VALUE; #if USE_2X UCSR0A = _BV(U2X0); #else UCSR0A &= ~_BV(U2X0); #endif UCSR0B = _BV(RXCIE0)| _BV(RXEN0) | _BV(TXEN0); UCSR0C = _BV(URSEL0) | _BV(UPM01) | _BV(UCSZ01); SREG = tmp; return; }
When writing to UCSR0C I set the URSEL0 bit as the datasheet states I should. Running through the code with my JTAGICE, I can see that OUT instruction does nothing. If I set the bits manually in the IO Viewer window, they are immediately cleared the next cycle. What is going on here?!
Thanks,
Jevin