大学生
最后登录1970-1-1
在线时间 小时
注册时间2017-7-24
|
- int main(void)
- {
- /*初始化USART 配置模式为 115200 8-N-1,中断接收*/
- USART_Config();
- USARTx_DMA_Config();
- LED_GPIO_Config();
-
- printf("欢迎使用野火STM32开发板\n\n\n\n");
-
- USART_DMACmd(DEBUG_USARTx, USART_DMAReq_Rx, ENABLE);
- while(1)
- {
- LED_RED;
- Delay(0xFFFFF);
- LED_YELLOW;
- Delay(0xFFFFF);
- if(USART_GetFlagStatus(DEBUG_USARTx,USART_FLAG_RXNE)==SET)
- {
- data=USART_ReceiveData(DEBUG_USARTx);
- USART_SendData(DEBUG_USARTx,data);
- USART_ClearFlag(DEBUG_USARTx,USART_FLAG_RXNE);
- }
- }
- }
复制代码- void USARTx_DMA_Config(void)
- {
- DMA_InitTypeDef DMA_InitStructure;
-
- // 开启DMA时钟
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
-
- DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)USART_DR_ADDRESS;
- DMA_InitStructure.DMA_MemoryBaseAddr = (u32)SendBuff;
- DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
- DMA_InitStructure.DMA_BufferSize = SENDBUFF_SIZE;
- DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
- DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
- DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
- DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
- DMA_InitStructure.DMA_Mode = DMA_Mode_Normal ;
- //DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
- DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
- DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
- DMA_Init(USART_TX_DMA_CHANNEL, &DMA_InitStructure);
-
- // 使能DMA
- DMA_Cmd (USART_TX_DMA_CHANNEL,ENABLE);
- }
复制代码 以上是我写的关于DMA外设到存储器的主函数和关于DMA配置的子函数,可是通过调试发现只能接收一个字符,不能和串口中断接收那样接受字符串和汉字,我后来在主函数if判断函数中嵌套了个【do——while】的循环函数,还是不行,并且把DMA_InitStructure.DMA_Mode的参数改为 DMA_Mode_Circular后也不行!请问各位大神怎么解决!!!!
|
-
|