程序如下,我初始化了DMA,在main函数里我不确定要不要加SPI_FLASH_BufferWrite(Tx_Buffer, FLASH_WriteAddress, BufferSize);不加没显示,加了我不确定DMA工作没。
int main(void)
{
/* 配置串口1为:115200 8-N-1 */
USART1_Config();
SPI_DMA_Config();
/* 2M串行flash W25Q16初始化 */
SPI_FLASH_Init();
/* Erase SPI FLASH Sector to write on */
SPI_FLASH_SectorErase(FLASH_SectorToErase);
/* 将发送缓冲区的数据写到flash中 */
SPI_FLASH_BufferWrite(Tx_Buffer, FLASH_WriteAddress, BufferSize);
SPI_I2S_DMACmd(SPI1,SPI_I2S_DMAReq_Tx,ENABLE);
printf("
写入的数据为:%s
", Tx_Buffer);
/* 将刚刚写入的数据读出来放到接收缓冲区中 */
SPI_FLASH_BufferRead(Rx_Buffer, FLASH_ReadAddress, BufferSize);
SPI_I2S_DMACmd(SPI1, SPI_I2S_DMAReq_Rx, ENABLE);
printf("
读出的数据为:%s
", Rx_Buffer);
}
void SPI_DMA_Config(){
DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
DMA_DeInit(DMA1_Channel2);//RX
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)0x4001300c;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)Rx_Buffer; // from function input parameter
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; // fixed for send function
DMA_InitStructure.DMA_BufferSize = BufferSize; // from function input parameter
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; // fixed
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; // fixed
DMA_InitStructure.DMA_PeripheralDataSize = DMA_MemoryDataSize_Byte; //fixed
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; //fixed
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; // fixed
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; // up to user
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; // fixed
DMA_Init(DMA1_Channel2, &DMA_InitStructure);
SPI1->CR2|= 1<<0;//接受缓冲区使能
DMA_Cmd(DMA1_Channel2,ENABLE);
DMA_DeInit(DMA1_Channel3);//TX
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)0x4001300c;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)Tx_Buffer; // from function input parameter
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; // fixed for send function
DMA_InitStructure.DMA_BufferSize = BufferSize; // from function input parameter
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; // fixed
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; // fixed
DMA_InitStructure.DMA_PeripheralDataSize = DMA_MemoryDataSize_Byte; //fixed
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; //fixed
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; // fixed
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; // up to user
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; // fixed
DMA_Init(DMA1_Channel3, &DMA_InitStructure);
//DMA_ITConfig(DMA1_Channel3, DMA_IT_TC, ENABLE);
SPI1->CR2|= 1<<1;//接受缓冲区使能
DMA_Cmd(DMA1_Channel3,ENABLE);
}
此帖出自
小平头技术问答
一周热门 更多>