完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
STM32F103C8T6单晶片,使用USART1+DMA接收资料,RX
DMA_BufferSize设定为30 bytes,当接收长度<30 bytes,进USART1_IRQHandler(void)的空闲中断,但当资料长度=30 bytes时,会先进DMA1_Channel5_IRQHandler(void)的DMA 传输缓冲完成中断,然後再进USART1_IRQHandler(void)的空闲中断,想请问当资料长度=DMA_BufferSize时,如何不要进空闲中断,谢谢! void RCC_Configuration(void) { RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA| RCC_APB2Periph_USART1 ,ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1,ENABLE); } void GPIO_Configuration(void) { GPIO_InitTypeDefGPIO_InitStructure; GPIO_DeInit(GPIOA); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //TX GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz; GPIO_Init(GPIOA,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin= GPIO_Pin_10; //RX GPIO_InitStructure.GPIO_Mode= GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed= GPIO_Speed_50MHz; GPIO_Init(GPIOA,&GPIO_InitStructure); } void USART_Configuration(void) { USART_InitTypeDefUSART_InitStructure; USART_DeInit(USART1); USART_InitStructure.USART_BaudRate= 115200; USART_InitStructure.USART_WordLength= USART_WordLength_8b; 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); USART_Cmd(USART1,ENABLE); USART_ITConfig(USART1,USART_IT_IDLE,ENABLE); } void DMA_Configuration(void) { DMA_InitTypeDefDMA_InitStructure; DMA_DeInit(DMA1_Channel4); DMA_InitStructure.DMA_PeripheralBaseAddr= (uint32_t)(&USART1->DR); DMA_InitStructure.DMA_MemoryBaseAddr= (uint32_t)TxBuffer; DMA_InitStructure.DMA_DIR= DMA_DIR_PeripheralDST; DMA_InitStructure.DMA_BufferSize= 256; 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_Priority= DMA_Priority_VeryHigh; DMA_InitStructure.DMA_M2M= DMA_M2M_Disable; DMA_Init(DMA1_Channel4,&DMA_InitStructure); DMA_Cmd(DMA1_Channel4,ENABLE); DMA_ITConfig(DMA1_Channel4,DMA_IT_TC| DMA_IT_TE,ENABLE); DMA_DeInit(DMA1_Channel5); DMA_InitStructure.DMA_PeripheralBaseAddr= (uint32_t)(&USART1->DR); DMA_InitStructure.DMA_MemoryBaseAddr= (uint32_t)RxBuffer; DMA_InitStructure.DMA_DIR= DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize= 30; 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_PeripheralDataSize_Byte; DMA_InitStructure.DMA_Mode= DMA_Mode_Normal; DMA_InitStructure.DMA_Priority= DMA_Priority_VeryHigh; DMA_InitStructure.DMA_M2M= DMA_M2M_Disable; DMA_Init(DMA1_Channel5,&DMA_InitStructure); DMA_Cmd(DMA1_Channel5,ENABLE); DMA_ITConfig(DMA1_Channel5,DMA_IT_TC| DMA_IT_TE,ENABLE); } void NVIC_Configuration(void) { NVIC_InitTypeDefNVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel= USART1_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority= 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority= 0; NVIC_InitStructure.NVIC_IRQChannelCmd= ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel= DMA1_Channel4_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority= 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority= 0; NVIC_InitStructure.NVIC_IRQChannelCmd= ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel= DMA1_Channel5_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority= 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority= 0; NVIC_InitStructure.NVIC_IRQChannelCmd= ENABLE; NVIC_Init(&NVIC_InitStructure); } void USART1_IRQHandler(void) { uint8_t clear; if(USART_GetITStatus(USART1,USART_IT_IDLE)!=RESET) // forUSART_IT_IDLE { clear = USART1->SR; //clear IT_IDLE clear = USART1->DR; data_len = 30- DMA_GetCurrDataCounter(DMA1_Channel5); DMA_Cmd(DMA1_Channel5,DISABLE); DMA_SetCurrDataCounter(DMA1_Channel5,30); DMA_Cmd(DMA1_Channel5,ENABLE); } } void DMA1_Channel4_IRQHandler(void) { if(DMA_GetITStatus(DMA1_FLAG_TC4)!= RESET) //for DMA_IT_TC { DMA_ClearITPendingBit(DMA1_IT_TC4); } } void DMA1_Channel5_IRQHandler(void) { if(DMA_GetITStatus(DMA1_IT_TC5)!= RESET) //for DMA_IT_TC { DMA_ClearITPendingBit(DMA1_IT_TC5); DMA_Cmd(DMA1_Channel5,DISABLE); DMA_SetCurrDataCounter(DMA1_Channel5,30); DMA_Cmd(DMA1_Channel5,ENABLE); } } |
|
相关推荐
5个回答
|
|
|
|
|
|
FPGA 开发十五年开发经验
|
|
|
|
把DMA发送中断关了,只用串口的空闲中断
|
|
|
|
我者是抄空闲中断来接收,效果还好,可以私聊我送你代码!
|
|
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
649 浏览 0 评论
使用stm32l451片子,对ad7606进行3通道100k采样值跳动问题?
1330 浏览 1 评论
STM32进行DMA数据转运,为什么只有A组最后一位数据被转运到B组去?
1780 浏览 2 评论
2071 浏览 3 评论
1660 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-9-1 21:24 , Processed in 0.696744 second(s), Total 81, Slave 63 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191