PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : SD-Karte antwortet nicht



DavidN
31.08.2007, 12:09
Ich versuche die SD Karte zu reseten, aber diese antwortet nicht mit 1 wie sie eigentlich sollte:



.def temp = r16
.def loop = r17

.org 0x000
rjmp RESET ;bei Reset
.org 0x002
rjmp EXT_INT0 ;INT0

RESET:
;----- Stack

ldi temp, low(RAMEND) ;Stackpointer
out SPL, temp

ldi temp, high(RAMEND)
out SPH, temp

;----- Kontrolllampen an Port A

ldi temp, 0xFF
out DDRA, temp

;----- SPI

ldi temp, 0b10110000 ;Datenrichtung von PORTB
out DDRB, temp

ldi temp, 0b01010011 ;Master setzen und Takt
out SPCR, temp

sbi PORTB, 4

ldi temp, 0b00000000 ;SPI freigeben, Takt
out SPSR, temp

;----- Interrupts

ldi temp, 0b00000010
out DDRD, temp

ldi temp, 0b00000011 ;Interrupt Reaktionsimpuls einstellen
out MCUCR, temp

ldi temp, 0b01000000 ;Interrupts enablen
out GICR, temp

sei ;Interuppts aktivieren


IDLE:
rjmp idle


EXT_INT0:
sbi PORTA, 0 ;Led einschalten (Signal) ##################################
rjmp RESET_SD
reti


;---Reset-----------------------------------------------------------------------

RESET_SD:
sbi PORTA, 1 ;Led einschalten (Signal) ##################################
ldi temp,0xFF ;10 Bytes Zeit
rcall SEND_SPI

ldi temp,0xFF
rcall SEND_SPI

ldi temp,0xFF
rcall SEND_SPI

ldi temp,0xFF
rcall SEND_SPI

ldi temp,0xFF
rcall SEND_SPI

ldi temp,0xFF
rcall SEND_SPI

ldi temp,0xFF
rcall SEND_SPI

ldi temp,0xFF
rcall SEND_SPI

ldi temp,0xFF
rcall SEND_SPI

ldi temp,0xFF
rcall SEND_SPI

cbi PORTB, 4 ;Reset Befehl -> 6 bytes

ldi temp,0x40
rcall SEND_SPI

ldi temp,0x00
rcall SEND_SPI

ldi temp,0x00
rcall SEND_SPI

ldi temp,0x00
rcall SEND_SPI

ldi temp,0x00
rcall SEND_SPI

ldi temp,0x95
rcall SEND_SPI

RESET_WAIT: ;auf Antwort warten
sbis PINA, 7 ; blinken während schleife ##########################################
sbi PORTA, 7

sbic PINA, 7
cbi PORTA, 7

ldi temp, 0xFF
rcall SEND_SPI

cpi temp, 0x01
out PORTA, temp

brne RESET_WAIT

cbi PORTA, 0 ;Led ausschalten (Signal) #######################################
sbi PORTB, 4

ldi temp,0xFF
rcall SEND_SPI
ret



SEND_SPI: ;SPI Daten senden (von temp)
out SPDR, temp
SPI_WAIT:
sbis SPSR, SPIF
rjmp SPI_WAIT
in temp, SPDR
ret



Durch die Leds, weiß ich dass er in die schleife reinläuft, aber der brne nie aktiviert wird.

angeschlossen ist wie auf ulrich radigs seite beschrieben

habs versucht so übersichtlich wie nur irgend möglich zu schreiben, aber verstehe nicht, wo die antwort bleibt.

DavidN
31.08.2007, 13:59
um es einfacher zu machen den quellcode zu interpredieren, schreib ich mal kurz den aufbau des Programms:

es gibt eine Methode SEND_SPI, die aus temp ein byte liest, das im SPI durchschiebt, und dann das empfangene byte in temp schreibt. Das heißt, temp ist der übergabe und rückgabe parameter

die methode reset_sd benutzt die methode send_spi, und ruft sie jedesmal auf um ein byte zu senden oder zu empfangen. wenn empfangen werden soll, dann wird einfach 0xFF geschickt und dann temp ausgelesen