Google
Showing posts with label atmega32. Show all posts
Showing posts with label atmega32. Show all posts

Jul 6, 2008

Trouble with Atmega32's USART BaudRate ?

If there is some problem with usart baudRate then.

I want to set the USART Baud Rate to 9600 bps using 8-N-1 config.

The atmega32 is running on its internal 1 MHz oscillator. While configuring the USART I have used:

UBRR = 6

As per the table given on the Page 165 of atmega32's datasheet.

The table has two columns for the given baudrate for U2X=0 and U2X=1... Can you tell me what does this mean? And what is U2X is referring to?

I have interfaced an Xbee transceiver by Maxstream with the USART which is set to work on 9600 bps but apparently the data is not being Tx/Rx correctly. Any inputs?

Answer :

Well, let's tell if you use 1MHz internal crystal, you will have about 7% error which is not reliable at all. If you want a ZERO error rate you need to use an external crystal which is a multiple of 1200. For example a 11.0592 MHz is a multiply of 1200


( 11059200 / 1200 = 9216 )

you may understand why this is so.

Anyway, this is configuration for UART port of ATMEGA32 ( no interrupt )

UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x06;


you may check it in ATMEGA32 datasheet. You will surely understand how these values are selected.

In another note , as a starter I suggest you to work with CodeVision AVR. You can write ANSI C in this compiler.
But if you are going to go forward I suggest you to use IAR AVR. That is the only C++ compiler for AVR. It would be amazing if you want to write C++ codes. Also you can use it's JTAG debugger which is a miracle. You can connect a JTAGICE to your micro and you can place breakepoints on lines you want your program to be break and the you can check EVERYTHING at breakpoints. For example you want to see when you arrive to a line in your program what is the value of X. You will simply drag and drop X to the watch list and you will see the value of X. You can even see you memory IN CIRCUIT.


You might be also interested in:

:: Answers of Microprocessor(8085) & Electronics FAQ
:: The 8085 Microprocessor Architecture Microprocessors & Interfacing
:: How to add two binary numbers without carry

serial Port interfacing with atmega

This is the program for the serial communication with my atmega32.


.include"m32def.inc"
.org 0000
rjmp main


main: ldi r16,low(ramend)
out SPL,r16
ldi r16,high(ramend)
out SPH,r16

ldi r18,0x00
out UBRRH,r18
ldi r18,0x19 ;setting baud rate of 2400 for 1MHZ
out UBRRL,r18
ldi r19,0x18
out UCSRB,r19 ;enabling RX & TX bits
ldi r19,0x86
out UCSRC,r19 ;setting aychronous mode with 1 stop
;& 1start bit & no parity
again: rcall usart_rx
rcall usart_tx
rjmp again




usart_rx: sbis UCSRA,RXC
rjmp usart_rx
in r17,UDR

ret


usart_tx: sbis UCSRA,UDRE
rjmp usart_tx
out UDR,r17
ret

;*************************

and set the settings in hyper terminal as

baud rate:2400
flow control:none

You might be also interested in:

:: Answers of Microprocessor(8085) & Electronics FAQ
:: The 8085 Microprocessor Architecture Microprocessors & Interfacing
:: How to add two binary numbers without carry

May 10, 2008

Serial Port interfacing with atmega

Here is the code to interface atmega32 and serial port.


.include"m32def.inc"
.org 0000
rjmp main


main: ldi r16,low(ramend)
out SPL,r16
ldi r16,high(ramend)
out SPH,r16

ldi r18,0x00
out UBRRH,r18
ldi r18,0x19 ;setting baud rate of 2400 for 1MHZ
out UBRRL,r18
ldi r19,0x18
out UCSRB,r19 ;enabling RX & TX bits
ldi r19,0x86
out UCSRC,r19 ;setting aychronous mode with 1 stop
;& 1start bit & no parity
again: rcall usart_rx
rcall usart_tx
rjmp again




usart_rx: sbis UCSRA,RXC
rjmp usart_rx
in r17,UDR

ret


usart_tx: sbis UCSRA,UDRE
rjmp usart_tx
out UDR,r17
ret

;*************************

and set the settings in hyper terminal as

baud rate:2400
flow control:none

;********
You might be also interested in:
:: centigrade (celsius) to fahrenheit calculation for 8086 Assembly Language
:: Data transfer instructions of 8086 microprocessor