#define RES_NOTRDY 3 /* 3: Not Ready */
#define RES_PARERR 4 /* 4: Invalid Parameter */
+
+#define SPI_MODE_0 (0<<CPOL)|(0<<CPHA)
+#define SPI_MODE_1 (0<<CPOL)|(1<<CPHA)
+#define SPI_MODE_2 (1<<CPOL)|(0<<CPHA)
+#define SPI_MODE_3 (1<<CPOL)|(1<<CPHA)
+#define SPI_MODE SPI_MODE_0
+
;------------------------------------------------
;
.macro spi_clkslow
.if MMC_DEBUG > 1
printstring "SPI_CLK_SLOW "
.endif
- ldi temp,(1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0) ;clk/128
+ ldi temp,SPI_MODE|(1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0) ;clk/128
out SPCR,temp
out SPSR,_0
.endm
.if MMC_DEBUG > 1
printstring "SPI_CLK_FAST "
.endif
- ldi temp,(1<<SPE)|(1<<MSTR) ;clk/4
+ ldi temp,SPI_MODE|(1<<SPE)|(1<<MSTR) ;clk/4
out SPCR,temp
#if MMC_SPI2X
ldi temp,(1<<SPI2X)
brne mmc_rdex
rcall spi_rcvr ;Shift in first byte.
+.if MMC_DEBUG > 3
+ printnewline
+ rcall printhex
+ printstring " "
+.endif
out SPDR,_255 ;Start shift in next byte.
mmc_rcv_rl:
sbiw yl,1
st z+,temp
spi_waitm
in temp,SPDR
+.if MMC_DEBUG > 3
+ rcall printhex
+ printstring " "
+.endif
out SPDR,_255
rjmp mmc_rcv_rl
mmc_rcv_rle:
st z+,temp ;Store last byte in buffer
+.if MMC_DEBUG > 3
+ printnewline
+.endif
rcall spi_wait ; while SPI module shifts in crc part1.
rcall spi_rcvr ;Read second crc.