# help wanted programming usart0 of atmega162

**URL:** <https://community.sparkfun.com/t/help-wanted-programming-usart0-of-atmega162/1987>\
**Category:** MicroMod\
**Tags:** avr-atmel\
**Created:** [May 31, 2006, 11:36am UTC](https://community.sparkfun.com/t/help-wanted-programming-usart0-of-atmega162/1987 "2006-05-31T11:36:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcmh82](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@jcmh82](https://community.sparkfun.com/u/jcmh82)\
**Post date:** [May 31, 2006, 11:36am UTC](https://community.sparkfun.com/t/help-wanted-programming-usart0-of-atmega162/1987/1 "2006-05-31T11:36:19Z")

</div>

Hello, im having big big problems programming usart0 of atmega162. Below is the code of my program. im using stk500.

please could you tell me how can i make it works?

tell me also if its possible the configuration of fuse and lock bits to compare with the one i have.

when i turn on the microcontroller (programmed) conected to the hyperterminal i doesnt anything.

i want 9600bauds, no parity, 8 bits and 1 stop bit.

believe me im dont know what to do because with atmega16 it worked well.

i dont know what im doing wrong but i hope you do. Some part in the code are in spanish, my mother tongue.

thakns you very very much.

#include \<avr/io.h\>

// PROTOTIPOS DE FUNCIONES UTILIZADAS

void serial\_init\_0 (void);

unsigned char serial\_recv\_0 (void);

void serial\_send\_0 (unsigned char);

void serial\_print\_0 (const char \*);

/\* Inicia el puerto de la UART0 \*/

void serial\_init\_0(void) {

#define BAUD 3686000/16/9600-1

UBRR0L = 23;//ESTO SE SACA DEL DATASHEET

//ACTIVAR ENVIO Y RECEPCION

UCSR0B = (1\<\<TXEN0)|(1\<\<RXEN0);

//TIPO DE FRAME

UCSR0C = (1\<\<URSEL0)|(1\<\<USBS0)|(3\<\<UCSZ00);

return;

}

/\* ESPERAR UN CARACTER Y DEVOLVERLO UART0\*/

unsigned char serial\_recv\_0 (void) {

/\* Esperar \*/

while (!(UCSR0A & (1 \<\< RXC0)));

/\* Devolver lo recibido\*/

return UDR0;

}

/\* ENVIAR UN CARACTER UART0\*/

void serial\_send\_0 (unsigned char c) {

/\* Esperar a que el buffer de envio estÃ© vacio\*/

while (!(UCSR0A & (1 \<\< UDRE0)));

/\* poner en UDR para enviarlo \*/

UDR0 = c;

return;

}

/\* ENVIA UNA CADENA POR EL PUERTO SERIE UART0\*/

void serial\_print\_0 (const char \*msg) {

while (\*msg != 0)

serial\_send\_0 (\*msg++);

return;

}

int main() {

int i;

serial\_print\_0(“Hello”);

}

---

<div class="post-metadata">

**Author:** ![andrey](https://avatars.discourse-cdn.com/v4/letter/a/73ab20/32.png) [@andrey](https://community.sparkfun.com/u/andrey)\
**Post date:** [June 24, 2006, 5:01am UTC](https://community.sparkfun.com/t/help-wanted-programming-usart0-of-atmega162/1987/2 "2006-06-24T05:01:52Z")

</div>

The first thing to check is the “clock divide by 8” fuse. If that is set, your clock is running at 1/8 the speed you think it’s running. I think it’s called CLKDIV or something similar. Also make sure the “output clock on pin PB0” (or whatever it is on your MCU) fuse isn’t set either. Also the #define BAUD in your setup routine isn’t being used for anything, but I assume that the value 23 is correct based on the table in the datasheet?
