Mega64 Fehler bei RET

Gast #1570660
Lesenswert?

Hallo,

ich habe nach der Umstellung vom Mega324P, mit dem alles lief, auf einen 
Mega64 das Problem dass er anscheinend nach einem rcall nicht richtig 
zurück springt. In der Simulation in AVR Studio funktioniert es zwar, 
aber auf dem Controller scheint er nicht zurück zu srpingen sondern 
weiter zu laufen. Nach ca 250µs (etwa 4000 cycles bei 16 MHz) kommt dann 
wieder mein Reset-Debug-Flag.

Hier mal der Code den ich zum testen und der Übersichtlichkeit halber in 
eine eigenes Programm gepackt hab. Wenn ich rcall/ret durch rjmp (die 
auskommentierten) ersetzte funktioniert es ohne Porbleme. Im komplexeren 
Orginalprogramm kann ich das aber so nicht lösen.
1
.include "m64def.inc" 
2

3
.def temp      = r16
4
.def data       = r17 
5

6
reset:
7
  sbi  porte, 7             ; Reset-Debug-Flag
8
  cbi  porte, 7
9
  sbi  porte, 7
10
  cbi  porte, 7
11

12
  ldi   temp, LOW(RAMEND)  ; Init stack pointer
13
  out   SPL, temp
14
  ldi   temp, HIGH(RAMEND)  
15
  out   SPH, temp
16
                           ; USB status flags
17
  cbi  DDRB, 6             ; PORTB 6 = RXF = input
18
  sbi  PORTB, 6            ; pull-up active
19
  cbi  DDRB, 7             ; PORTB 7 = TXE = input
20
  sbi  PORTB, 7            ; pull-up active
21

22
                           ; USB control pins
23
  sbi  DDRB, 4             ; PORTB 4 = RD = output
24
  sbi  PORTB, 4            ; set it high
25
  sbi  DDRB, 5             ; PORTB 5 = WR = output
26
  cbi  PORTB, 5            ; set it low
27

28

29
main:
30
  rcall  read_byte_usb
31
;  rjmp  read_byte_usb
32

33
write_byte_usb:
34
  ldi   temp, 0xFF  
35
  out   DDRE, temp         ; PORTD is output
36

37
  out  PORTE, data
38
  cbi  PORTB, 5
39
  sbi  PORTB, 5
40
  
41
  rjmp  main
42

43
read_byte_usb:
44
  ldi  temp, 0x00  
45
  out  DDRE, temp          ; PORTE is input
46
  ldi  temp, 0xFF
47
  out  PORTE, temp         ; pull-ups active
48

49
wait_for_RXF:
50
  sbis PINB, 6             ; exit wait loop if RXF (read ready) is low
51
  rjmp read_byte
52
  rjmp wait_for_RXF
53

54
read_byte:
55
  cbi  PORTB, 4            ; pull RD low to read from usb chip
56
  nop                      ; !!! KEEP THIS FOR TIMING !!!
57
  in   data, PINE          ; read
58
  sbi  PORTB, 4           ; set RD to high again
59
  ret
60
;  rjmp  write_byte_usb

Schonmal vielen Danke für etwaige Tips

grüße
christian

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren