用DMA模式读写SD卡

2019-03-23 19:52发布

不好意思, 我知道这个问题问了很多次,可是我是一个新手,没有办法做到。我模仿了以下的程式:http://bbs.eeworld.com.cn/thread-250154-2-1.html
这是我的Code:void WriteBlock_DMA(void){ //__IO uint32_t Status = 0; uint8_t write_data[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; //SD_Init(); //Status = SD_WriteBlock(write_data, 0x00, SD_BLOCK_SIZE);
DMA_InitTypeDef DMA_TestStructure; SD_Error rvalue = SD_RESPONSE_FAILURE; SD_Init(); SD_CS_LOW(); //Enables the DMA1 peripheral clock. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); //Configuration of the DMA1 Channel4 - SPI2_RX DMA_DeInit(DMA1_Channel5);  DMA_TestStructure.DMA_PeripheralBaseAddr = (uint32_t)SD_SPI_DR_Address;  DMA_TestStructure.DMA_MemoryBaseAddr = (uint32_t)write_data;  DMA_TestStructure.DMA_DIR = DMA_DIR_PeripheralDST;  DMA_TestStructure.DMA_BufferSize = SD_BLOCK_SIZE;  DMA_TestStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;  DMA_TestStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;  DMA_TestStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;  DMA_TestStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;  DMA_TestStructure.DMA_Mode = DMA_Mode_Normal;  DMA_TestStructure.DMA_Priority = DMA_Priority_High;  DMA_TestStructure.DMA_M2M = DMA_M2M_Disable;  DMA_Init(DMA1_Channel5, &DMA_TestStructure); SD_SendCmd(SD_CMD_SET_BLOCKLEN,SD_BLOCK_SIZE,0x00);   SD_ReadByte();  SD_ReadByte(); SPI_I2S_DMACmd(SD_SPI, SPI_I2S_DMAReq_Tx, ENABLE); //DMA_ClearFlag(DMA1_FLAG_TC4); SD_SendCmd(SD_CMD_WRITE_SINGLE_BLOCK, 0x00, 0xFF); if (!SD_GetResponse(SD_RESPONSE_NO_ERROR))  {    /*!< Send a dummy byte */    SD_WriteByte(SD_DUMMY_BYTE);
    /*!< Send the data token to signify the start of the data */    SD_WriteByte(0xFE);     DMA_Cmd(DMA1_Channel5, ENABLE); while (!DMA_GetFlagStatus(DMA1_FLAG_TC5)); while(SPI_I2S_GetFlagStatus(SD_SPI, SPI_I2S_FLAG_TXE) == RESET); SD_ReadByte();    SD_ReadByte();     /* Read data response */    if (SD_GetDataResponse() == SD_DATA_OK)    {        rvalue = SD_RESPONSE_NO_ERROR;    } } SD_CS_HIGH();   SD_WriteByte(SD_DUMMY_BYTE); DMA_Cmd(DMA1_Channel5, DISABLE);}
程式一直停在if (SD_GetDataResponse() == SD_DATA_OK),请问各位高手我有哪里没有考虑到的吗? 此帖出自小平头技术问答
0条回答

一周热门 更多>