STM32F407的串口采用DMA收发数据
时间:11-19
来源:互联网
点击:
(void){//定义中断结构体NVIC_InitTypeDef NVIC_InitStructure ;//定义IO初始化结构体GPIO_InitTypeDef GPIO_InitStructure;//定义串口结构体 USART_InitTypeDef USART_InitStructure;//定义DMA结构体DMA_InitTypeDef DMA_InitStructure;//打开串口对应的外设时钟 RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);//串口发DMA配置 //启动DMA时钟RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);//DMA发送中断设置NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream6_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);//DMA通道配置DMA_DeInit(DMA1_Stream6);DMA_InitStructure.DMA_Channel = DMA_Channel_4; //外设地址DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(&USART2->DR);//内存地址DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Tx_Buf_Gsm;//dma传输方向DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;//设置DMA在传输时缓冲区的长度DMA_InitStructure.DMA_BufferSize = TX_LEN_GSM;//设置DMA的外设递增模式,一个外设DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//设置DMA的内存递增模式DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//外设数据字长DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;//内存数据字长DMA_InitStructure.DMA_MemoryDataSize = DMA_PeripheralDataSize_Byte;//设置DMA的传输模式DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;//设置DMA的优先级别DMA_InitStructure.DMA_Priority = DMA_Priority_High;//指定如果FIFO模式或直接模式将用于指定的流 : 不使能FIFO模式 DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; //指定了FIFO阈值水平DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; //指定的Burst转移配置内存传输 DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; //指定的Burst转移配置外围转移 */ DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; //配置DMA1的通道 DMA_Init(DMA1_Stream6, &DMA_InitStructure); //使能中断DMA_ITConfig(DMA1_Stream6,DMA_IT_TC,ENABLE); //串口收DMA配置 //启动DMA时钟RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);//DMA通道配置DMA_DeInit(DMA1_Stream5);DMA_InitStructure.DMA_Channel = DMA_Channel_4;//外设地址DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)(&USART2->DR);//内存地址DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Rx_Buf_Gsm;//dma传输方向DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;//设置DMA在传输时缓冲区的长度DMA_InitStructure.DMA_BufferSize = RX_LEN_GSM;//设置DMA的外设递增模式,一个外设DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//设置DMA的内存递增模式DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//外设数据字长DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;//内存数据字长DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;//设置DMA的传输模式DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;//设置DMA的优先级别DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;//指定如果FIFO模式或直接模式将用于指定的流 : 不使能FIFO模式 DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; //指定了FIFO阈值水平DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; //指定的Burst转移配置内存传输 DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; //指定的Burst转移配置外围转移 */ DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; //配置DMA1的通道 DMA_Init(DMA1_Stream5, &DMA_InitStru
STM32F407串口DMA收发数 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)