uint8_t SD_READ uint32_t sector if CADR_TYPE SPISD_VER2HC sector 512 i

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
uint8_t SD_READ(uint32_t sector)
{
//if (CADR_TYPE != SPISD_VER2HC)
sector *= 512;
if (SPI_CMD(17, sector, 0x0, 0x00)) return 1;
CS();
R1 = 0;
while(SPI_SEND(0xFF) != 0xFE) //НАЧАЛО ДАННЫХ
{
if(R1++ > 0xFFFE)
{
DECS();
return 1;
}
}
//Выключаем
DMA_Cmd(DMA2_Channel1, DISABLE);
DMA_Cmd(DMA2_Channel2, DISABLE);
//Перезагрузка каналов
DMA_SetCurrDataCounter(DMA2_Channel1, 512);
DMA_SetCurrDataCounter(DMA2_Channel2, 512);
//Поехали...
DMA_Cmd(DMA2_Channel1, ENABLE);
DMA_Cmd(DMA2_Channel2, ENABLE);
//Приняли сектор
while(!DMA_GetFlagStatus(DMA2_FLAG_TC1));
while(!DMA_GetFlagStatus(DMA2_FLAG_TC2));
//Сбросили Трансфер комплект
DMA_ClearFlag(DMA2_FLAG_TC1);
DMA_ClearFlag(DMA2_FLAG_TC2);
//for(R2 = 0; R2 < 512; R2++)
//{
//SD_SPI->DR = 0xFF;
//while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE) == RESET)
//{
// }
// BUFFER[R2] = SPI3->DR;
//BUFFER[R2]= SPI_SEND(0xFF);
//}
SD_SPI->DR = 0xFF;
SD_SPI->DR = 0xFF;
SD_SPI->DR = 0xFF;
DECS();
return 0;
}