Full Version : USART0 with ATMEGA162!
avr >>C PROGRAMMING (AVR) >>USART0 with ATMEGA162!


lpalma- 07-29-2006
Hi everyone...

i´m triyng to program the usart0 of the atmega162, but i have <0><0>.... as result :((

here the code that i´m using:

CODE

//Inicialization
// enable RxD/TxD and interrupts
outb(UCSR0B, BV(RXCIE)|BV(TXCIE)|BV(RXEN)|BV(TXEN));
outb(UCSR0C,_BV(UCSZ01)|_BV(UCSZ00)); // 8bits, 1stop, no parity
// set default baud rate
uartSetBaudRate(0, UART0_DEFAULT_BAUD_RATE); //9600


void uartSetBaudRate(u08 nUart, u32 baudrate)
{
// calculate division factor for requested baud rate, and set it
u08 baudrateDiv;
baudrateDiv = (u08)((F_CPU+(baudrate*8L))/(baudrate*16L)-1);
if(nUart)
outb(UBRR1L, baudrateDiv);
else
outb(UBRR0L, baudrateDiv);
}


UART_INTERRUPT_HANDLER(SIG_USART0_TRANS)
{// check if buffered tx is enabled
if(uartBufferedTx[nUart])
{
// check if there's data left in the buffer
if(uartTxBuffer[nUart].datalength)
{
// send byte from top of buffer
if(nUart)
outb(UDR1, bufferGetFromFront(&uartTxBuffer[1]) );
else
outb(UDR0, bufferGetFromFront(&uartTxBuffer[0]) );
}
else
{
// no data left
uartBufferedTx[nUart] = FALSE;
// return to ready state
uartReadyTx[nUart] = TRUE;
}
}

else
{
// we're using single-byte tx mode
// indicate transmit complete, back to ready
uartReadyTx[nUart] = TRUE;
}
}



//Main
...
rprintfInit(uart0SendByte); // configure rprintf to use UART0 for output
rprintf("1234567890"); // send "1234567890" message via UART0



Can anyone help me...

Thanks
Best regards


Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.