I try to transmit data from my Atmega168A-PU to my computer using the USART. To do so I have written the following code:
#include <avr/io.h>
#include <stdlib.h>
#define F_CPU 8000000UL
#define USART_BAUD 9600
#define UBRR_VALUE (F_CPU/16/USART_BAUD - 1)
void
usart_init(void)
{
UBRR0H = (unsigned char)(UBRR_VALUE >> 8);
UBRR0L = (unsigned char)UBRR_VALUE;
UCSR0B = _BV(TXEN0) | _BV(UDRIE0);
UCSR0C = _BV(USBS0) | _BV(UCSZ00) | _BV(UCSZ01);
//UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
}
ISR(USART0_UDRE_vect)
{
UDR0 = '0';
UCSR0A |= _BV(TXC0);
}
int main(void)
{
usart_init();
while(!(UCSR0A & _BV(UDRE0)));
UDR0 = '0';
while(1);
return 0;
}
I have attached the Arduino USB2SERIAL converter to read the values on my computer, however the converter says that he does not receive data and my computer does not receive data either.
Note: My lfuse is 0xe2 (CLKDIV8 disabled), so I have 8MHz F_CPU.
Note: I tried without the UCSR0A |= _BV(TXC0);, too.
Note: I have a capacitor between AVcc and AGnd.
Note: Fuses: (E:F9, H:DF, L:E2)