Forum: Projekte & Code USART ATmega128


von Hilel1 (Gast)


Lesenswert?

Hallo zusammen.

Ich habe folgendes Programm zum Testen der RS232(1) beim ATmega128 
geschrieben. Es soll im Zusammenspiel mit Hyperterminal die serielle 
Übertragung vom und zum uC testen.

;.nolist
.include  "m128def.inc"
;.list

.def  temp1=r16
.def  temp2=r17

.equ  CLOCK = 16000000
.equ  BAUD  = 9600
.equ  UBRRVAL = CLOCK / (BAUD*16)-1

.cseg
.org 0x0000

start:
    rcall   initRAM
  rcall   initUART
loop:
  rcall   receive
  rcall   transmit
  rjmp  loop


initRAM:
  ldi  temp1,High(RamEnd)
  out  sph,temp1
  ldi  temp1,Low(RamEnd)
  out  spl,temp1
  ret

initUART:


  ldi  temp1,High(UBRRVAL)
  sts  UBRR1H,temp1
  ldi  temp1,Low(UBRRVAL)
  sts  UBRR1L,temp1

  ldi temp1,(1<<RXEN1) | (1<<TXEN1)  ;
  sts  UCSR1B,temp1          ; Senden und Empfangen aktiv
  ldi  temp1,(1<<UCSZ11) | (1<<UCSZ10)  ; 8 Bit, 1 Stopbit
  sts  UCSR1C,temp1

  ret

transmit:
  lds    temp1,UCSR1A
  sbrs  temp1,UDRE1          ; warten bis UART bereit ist
  rjmp  transmit
  sts    UDR1,temp2
  ret

receive:
  lds    temp1,UCSR1A
  sbrs  temp1,RXC1
  rjmp  receive
  lds    temp2,UDR1
  ret

Ich bringe es nicht zum Laufen.
In C war es kein Problem. Es hat auf Anhieb funktioniert.
Hat jemand eine Idee?
Danke im voraus

von Moi (Gast)


Lesenswert?

Du ruftst eine Funktion auf, bevor der Stack initialisert ist. Ist das 
Gut?!

initRAM und initUART würde ich direkt einbinden. Warum sollte man das 
callen?! Wird ja eh nur einmal ausgeführt.

von Hilel1 (Gast)


Lesenswert?

Hallo Moi.
Da hast Du recht. Da habe ich nicht aufgepasst.
Das ursprüngliche Programm sieht eigentlich so aus:

;.nolist
.include  "m128def.inc"
;.list

.def  temp1=r16
.def  temp2=r17

.equ  CLOCK = 16000000
.equ  BAUD  = 9600
.equ  UBRRVAL = CLOCK / (BAUD*16)-1

.cseg
.org 0x0000

start:
  ldi  temp1,High(RamEnd)        ; RAM initialisieren
  out  sph,temp1
  ldi  temp1,Low(RamEnd)
  out  spl,temp1

  ldi temp1,(1<<RXEN1) | (1<<TXEN1)  ;
  sts  UCSR1B,temp1  ; Senden und Empfangen aktiv
  ldi  temp1,(1<<UCSZ11) | (1<<UCSZ10)  ; 8 Bit, 1 Stopbit
  sts  UCSR1C,temp1

  ldi  temp1,High(UBRRVAL); Baudrate
  sts  UBRR1H,temp1
  ldi  temp1,Low(UBRRVAL)
  sts  UBRR1L,temp1

loop:
  rcall   receive
  rcall   transmit
  rjmp  loop

transmit:
  lds  temp1,UCSR1A
  sbrs  temp1,UDRE1  ; warten bis UART bereit ist
  rjmp  transmit
  sts  UDR1,temp2
  ret

receive:
  lds  temp1,UCSR1A
  sbrs  temp1,RXC1
  rjmp  receive
  lds  temp2,UDR1
  ret

Ist schon merkwürdig mit dem Hyperterminal. Warum funzt das Programm so 
nicht?

von spess53 (Gast)


Lesenswert?

Hi

>Ist schon merkwürdig mit dem Hyperterminal. Warum funzt das Programm so
>nicht?

Was geht nicht? Kann auch an deiner Hardware liegen.

MfG Spess

von Hilel1 (Gast)


Lesenswert?

Die HW ist schon in Ordnung. Wie gesagt, in C hat es auf anhieb 
funktioniert.
Es lag wohl an dem Hyperterminal. Heute morgen ging es plötzlich.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.