Go Down

Topic: Extra characters in UART (Read 435 times) previous topic - next topic

solarrobor

Hi

I am getting extra characters at the end of a string I am sending via UART to my PC. I am sending the string "North: 0x" and I get the following output (as seen in Hyperterminal):
N   o  r   t   h   :       0   x %(without the spaces and % representing the extra characters)
4E 6F 72 74 68 3A 20 30 78 0F 00 00 00 0D 0A (hexadecimal representation)
with the extra characters being the 0x0F 0x00 0x00 0x00.

My code extract is as follows:
Code: [Select]

   ; print "North :"
   ldi r31, HIGH(2*north_txt)
   ldi r30, LOW(2*north_txt)
   rcall print_string

...

init_uart:
   ; UART SETUP
   ;------------
   ; baud rate passed via registers r17(H) and r16(L)
   sts UBRR0H, r17
   sts UBRR0L, r16
   ; enable Tx and RX
   ldi r16, (1 << RXEN0 | 1 << TXEN0)
   sts UCSR0B, r16
   ; frame format - 8bits, no parity, 1 stop bit
   ldi r16, (1 << UCSZ01 | 1 << UCSZ00)
   sts UCSR0C, r16
   ret

...

; data to be transmitted must be loaded into
; register r16
print_char:
   lds r17, UCSR0A
   sbrs r17, UDRE0
   rjmp print_char
   sts UDR0, r16
   ret

print_string:
   lpm r16, Z+
   ; check for end of string
   cpi r16, 0x00
   breq eof
   rcall print_char
   ; next character
   rjmp print_string

north_txt: .db "North: 0x", 0x00


I am using AVR Studio 4 on a Windows XP SP3 to program the Atmega328P on an Arduino Duemilanove.

Has anybody had the same problem and how do I resolve it?

Go Up