读多块:u8 SD_ReadMultiBlock(u32 sector, u8 *buffer, u8 count)
{
u8 r1;
SPI_SetSpeed(SPI_SPEED_HIGH);
if(SD_Type != SD_TYPE_V2HC)
{
sector = sector<<9;
}
r1 = SD_SendCommand(CMD18, sector, 1); //读多块命令
if(r1 != 0x00) return r1;
do //开始接收数据
{
if(SD_ReceiveData(buffer, 512, NO_RELEASE) != 0x00)
{
break;
}
buffer += 512;
} while(--count);
SD_SendCommand(CMD12, 0, 1); //全部传输完成,发送停止命令
SD_CS_DISABLE(); //释放总线
SPI_ReadWriteByte(0xFF);
if(count != 0)
return count; //如果没有传完,返回剩余个数
else
return 0;
}
|