RadioLocman.com Electronics ru
Advanced Search +
  
Go Back   RadioLocman Forum > Electronics and ... > Microcontrollers (MCU)

Microcontrollers (MCU) Application and programming of MCUs, Evaluation Kits and Demonstration Boards, Programmers.

Reply
 
Thread Tools Search this Thread
Old 10-27-2013, 01:47 PM   #1
Anatoly
Member
 
Join Date: Oct 2013
Posts: 57
Anatoly is on a distinguished road
Default UART Atmega128 is not working

Hello. Cannot run the uart on the Atmega128. For a week now trying to solve this issue.
Maybe speed error or configuration bits?
The code of the program and the schematic are below.
Code:
.include "m1281def.inc"
.equ XTAL_CPU		= 8000000			; CPU (4MHz)
.equ baudrate 		= 9600
.equ bauddivider 	= XTAL_CPU/(16*baudrate)-1

.org 0		
		
		ldi r16,low(ramend)  ;RAM
		out spl,r16	
		ldi r16,high(ramend)
		out sph,r16	
								
									;initialize device USART0
		ldi	r17,high(bauddivider)	;9600
		ldi	r16,low(bauddivider)
		sts	UBRR0L,r17				; baud rate UBRRL:UBRRH
		sts	UBRR0H,r16
		ldi	r16, 0b00011000			;ON RX/TX
		sts	UCSR0B,r16
		ldi	r16, 0b00000110			; async mode,parity off,1stop bit,8data
		sts	UCSR0C,r16


		ser	r18
		sts	UDR0,r18				;out UART

main:
	rjmp main
Attached Images
File Type: jpg pic1.JPG (93.8 KB, 7 views)

Last edited by Anatoly; 10-27-2013 at 02:22 PM.
Anatoly is offline   Reply With Quote
Old 10-29-2013, 08:27 AM   #2
Vadzz
Member
 
Join Date: Jan 2011
Posts: 63
Vadzz is on a distinguished road
Default

You incorrectly initialize the UART0. And you chose the wrong *. inc file: instead m1281def.inc need m128def.inc.

Here is a sample code to initialize:
Code:
;UART0 init				
      LDI R16, low(bauddivider)
      OUT UBRR0L,R16
      LDI R16, high(bauddivider)
      STS UBRR0H,R16
      LDI R16,0
      OUT UCSR0A, R16
      LDI R16, (1 << RXEN0)|(1 << TXEN0)|(0 << RXCIE0)|(0 << TXCIE0)
; Interrupts disabled, RX-TX enabled.
      OUT UCSR0B, R16
      LDI R16, (1 << UCSZ00)|(1 << UCSZ01)
; 8data
      STS UCSR0C, R16
And use the AVR Studio built-in simulator, there you step through the program clearly shows the change of the microcontroller registers.

Last edited by Vadzz; 10-29-2013 at 09:46 AM.
Vadzz is offline   Reply With Quote
Old 11-01-2013, 03:09 PM   #3
Anatoly
Member
 
Join Date: Oct 2013
Posts: 57
Anatoly is on a distinguished road
Default

Thank you. You to help me. Now everything works.
Attached Images
File Type: jpg 2.JPG (157.9 KB, 4 views)
Anatoly is offline   Reply With Quote
Old 11-01-2013, 04:00 PM   #4
Vadzz
Member
 
Join Date: Jan 2011
Posts: 63
Vadzz is on a distinguished road
Default

You're welcome. I was glad to help you...
Vadzz is offline   Reply With Quote
Old 01-24-2016, 03:11 PM   #5
smartic
Junior Member
 
Join Date: Jan 2016
Posts: 1
smartic is on a distinguished road
Default

How to change the data rate?
smartic is offline   Reply With Quote
Old 01-25-2016, 09:13 AM   #6
hemilton
Member
 
Join Date: Nov 2013
Posts: 46
hemilton is on a distinguished road
Default

change .equ baudrate
hemilton is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Discussion: Simple solenoid driver is adaptable and efficient Radiolocman Robot Projects and Advices 1 02-28-2013 08:55 AM

All times are GMT. The time now is 07:34 AM.




Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Slices ↓
Radiolocman facebook Radiolocman twitter Radiolocman google plus