u8 SD_Write_MultiBlock(u32 sector, const u8 *data, u8 count)
{
u8 r1;
u16 i;
if(SD_Type != SD_TYPE_V2HC)
{
sector = sector<<9;
}
if(SD_Type != SD_TYPE_MMC)
r1 = SD_Send_Command(ACMD23, count, 0x00,RELEASE);
r1 = SD_Send_Command(CMD25, sector, 0x00,RELEASE);
if(r1 != 0x00)
return r1;
SD_CS_L;
SPIx_ReadWrite_Byte(0xff);
SPIx_ReadWrite_Byte(0xff);
SPIx_ReadWrite_Byte(0xff);
do
{
SPIx_ReadWrite_Byte(0xFC);
for(i=0;i<512;i++)
{
SPIx_ReadWrite_Byte(*data++);
}
SPIx_ReadWrite_Byte(0xff);
SPIx_ReadWrite_Byte(0xff);
r1 = SPIx_ReadWrite_Byte(0xff);
if((r1&0x1F)!=0x05)
{
SD_CS_H;
return r1;
}
if(SD_Wait_DataReady()==1)
{
SD_CS_H;
return 1;
}
}while(--count);
r1 = SPIx_ReadWrite_Byte(0xFD);
if(r1==0x00)
{
count = 0xfe; //???????????????????????????????????????
}
if(SD_Wait_DataReady()) //等待数据写入完成
{
SD_CS_H;
return 1;
}
SD_CS_H;
SPIx_ReadWrite_Byte(0xff);
return count;
}
上面问号处,是什么意思呢?
写入停止0xFD后,即 r1 = SPIx_ReadWrite_Byte(0xFD); 如何响应的? count = 0xfe; 为什么写入的扇区个数为这个值呢?
|