uart output problem

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've looked at this till I'm bored... the output string is being output twice. Can anybody shed some light? I'm no expert on AVR assembler... This is just the start of a project and I want to be able to output data to a pc as a debugging aid, so I have to get this going first. Thought it might be the Wdog, but no... :(
I's for a Mega8 running Xtal at 3.6848.
Here's the code:-

.org 0
rjmp start

.org 0x100

start:
ldi R24, low(RAMEND) ; SP = RAMEND
ldi R25, high(RAMEND)
out SPL, R24
out SPH, R25

ldi rParam1, 47 ; Baud rate = 4800 at 3.684mhz
out UBRRL, rParam1

ldi R24,(1<<RXEN)|(1<<TXEN) ; Enable receiver & transmitter, 8-bit mode
out UCSRB,R24

ldi r16, (1<<URSEL)|(3<<UCSZ0)
out UCSRC,r16

in r16, WDTCR
ori r16, (1<<WDCE)|(1<<WDE)
out WDTCR, r16
; Turn off WDT
ldi r16, (0<<WDE)
out WDTCR, r16
CLI

ldi ZL,low(2*TestOutput) ; load the start-address of the startup message
ldi ZH,high(2*TestOutput) ; into the Z-Register

str_output:
lpm rPayload,Z+ ; read one character of the string and increment
tst rPayload ;test if chr = 0
breq L10 ; exit the character output loop if character is '0'

rcall uartSend ; send the read character via the UART
rjmp str_output ; go to start of loop for next character

uartSend:
sbis UCSRA,UDRE ; wait for empty transmit buffer (until UDRE==1)
rjmp uartSend
out UDR,rPayload ; UDR = R16, start transmission
ret
L10:
rjmp pc

TestOutput:

.db "Transmit address is :-",10,13,0

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I've looked at this till I'm bored...

... and I'm not bored enough to decipher a flush-left piece of code. Please repost with the "Code" tags and some structure.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your code works just fine in the simulator.

rjmp pc

I would change this to:

rjmp L10

I think it makes it clearer.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What's a 'flush left' piece of code?
@Koshchi.... I should have mentioned that it seems to be OK on the simulator, and assembleing with L10 or PC gives the same hex code- cfff for the jump...
Bored was the wrong word.... I was frustrated that I couldn't get it working.It's not exactly complicated.
Anyway, I checked it on the scope and it gives one string O/P. Cut a long story short, if I disconnect the AVRISPMK11 it works properly......

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
if I disconnect the AVRISPMK11 it works properly......
:shock:?? So disconnect it. The programmer may influence the reset pin.

Do you have a proper reset network with a pullup resistor and a cap to ground?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@JS Thanks for the info, there's nothing on the reset pin. I'll see if that fixes it tomorrow... I'm just happy it works for now. :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
What's a 'flush left' piece of code?

It's a piece of code with no indentation which makes it almost impossible to follow the structure as the labels are intermingled with the opcodes.

Here's some of your original post:

ldi ZL,low(2*TestOutput) ; load the start-address of the startup message
ldi ZH,high(2*TestOutput) ; into the Z-Register

str_output:
lpm rPayload,Z+ ; read one character of the string and increment
tst rPayload ;test if chr = 0
breq L10 ; exit the character output loop if character is '0'

rcall uartSend ; send the read character via the UART
rjmp str_output ; go to start of loop for next character

uartSend:
sbis UCSRA,UDRE ; wait for empty transmit buffer (until UDRE==1)
rjmp uartSend
out UDR,rPayload ; UDR = R16, start transmission
ret
L10:
rjmp pc

and this is what it looks like with code tags:

 	ldi ZL,low(2*TestOutput)  	; load the start-address of the startup message 
	ldi ZH,high(2*TestOutput)  	; into the Z-Register

str_output: 
 	lpm rPayload,Z+ 		; read one character of the string and increment 
 	tst rPayload			;test if chr = 0
 	breq L10  			; exit the character output loop if character is '0' 

	rcall uartSend			; send the read character via the UART
 	rjmp str_output 		; go to start of loop for next character

uartSend: 
 	sbis UCSRA,UDRE  		; wait for empty transmit buffer (until UDRE==1)
 	rjmp uartSend
 	out UDR,rPayload  		; UDR = R16, start transmission
 	ret
L10:	
	rjmp pc

(OK I'll admit that the wrapping of your long comments doesn't exactly help readability! ;) )

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for that, I see what you mean... the code is tabbed away from the labels...