Pages: [1]   Go Down
Author Topic: Extra characters in UART  (Read 413 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
   ; 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?
Logged

Pages: [1]   Go Up
Jump to: