[mw_shl_code=c,true]debug看到USART->DR里面是有数据的,IDLE中断也能进去,但是貌似DMA不工作[/mw_shl_code]
[mw_shl_code=c,true]
[mw_shl_code=c,true]DMA_GetCurrDataCounter(DMA2_Stream2);一直是0[/mw_shl_code]
串口配置如下
[/mw_shl_code]
[mw_shl_code=c,true]void UART1_Config(u32 bound)
{
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //开GPIOA时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);//开USART1时钟
//串口1对应引脚复用映射
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1); //GPIOA9?复用为USART1
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1); //GPIOA10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; //GPIOA9与GPIOA10
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO速度50M
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推免复用输出
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
GPIO_Init(GPIOA,&GPIO_InitStructure); //初始化IO
//USART1 初始化
USART_InitStructure.USART_BaudRate = bound;//波特率设置
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//8bit
USART_InitStructure.USART_StopBits = USART_StopBits_1;//停止位
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //打开发送和接收
USART_Init(USART1, &USART_InitStructure); //初始化串口1
USART_Cmd(USART1, ENABLE); //开启串口1
USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE);
//USART_ClearFlag(USART1, USART_FLAG_TC);
//中断设置
USART_ITConfig(USART1, USART_IT_IDLE, ENABLE);//空闲中断
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;//串口1中断通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;//抢占优先级3
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0; //子优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //初始化
//DMA使能
RCC_AHB1PeriphResetCmd(RCC_AHB1Periph_DMA2, ENABLE); //??DMA??
DMA_DeInit(DMA2_Stream2); //DeInit
DMA_InitStructure.DMA_Channel = DMA_Channel_4; //通道选择
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)(&(USART1->DR));//源地址
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Uart_Rx1; //目的地址
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; //外设到内存
DMA_InitStructure.DMA_BufferSize = UART1_RX_LEN; //数据传输量
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//外设非增量模式
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //内存增量模式
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;//数据长度8bit
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; //存储器数据长度8bit
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; //普通模式
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; // 优先级高
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;//存储器突发单次传输
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;//外设突发单次传输
DMA_Init(DMA2_Stream2, &DMA_InitStructure);//初始化
DMA_Cmd(DMA2_Stream2,ENABLE); //使能
}[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
发送完,可重载
一周热门 更多>