Ejemplo n.º 1
0
byte MMC_ReadSector(byte *buffer, uint32_t sector)
{
	if (!(_mmcState & MMC_INITED))
		return MMC_NOT_INITED;
	if (!(_mmcState & MMC_HIGH_DENSITY))
		sector <<= 9;
	MMC_SS_LOW();
	if (MMC_Command(17,sector) != 0 || MMC_Token() != 0xFE)
		return MMC_Release(READ_FAILED);
	SPI_Receive(buffer,512);	// WARNING! Will strip 2 CRC bytes as well
	return MMC_Release(0);
}
Ejemplo n.º 2
0
byte MMC_Command(byte cmd, uint32_t param)
{
	byte* b = (byte*)&param;
	byte csum = 0xFF;
	if (cmd == 0)
		csum = 0x95;
	else if (cmd == 8)
		csum = 0x87;	// Avoid checksum code
	byte d[7];
	d[0] = 0xFF;
	d[1] = cmd + 0x40;
	d[2] = b[3];
	d[3] = b[2];
	d[4] = b[1];
	d[5] = b[0];
	d[6] = csum;
	SPI_Send(d,7);
	return MMC_Token();
}