个位达人,我使用USART2的TX做DMA进行数据的输出,波特率为115200,直接发送给PC机,每次发送结束后,进入DMA7的中断,关闭DMA通道。 在PC机发来数据后,又进入USART2的RX中断,在中断里重新再设置DMA的收发地址和字节数,再次发送。
通讯上了,可奇怪的是每次都还没有把设定的字节数读完,就进入了DMA7的中断(我设置的是发完再中断),总会少两个字节。
在DMA7的中断里加上while(!USART2.SR.B.TC);后就OK了,这是否可以说明,在尚未全部发完的情况下,就已经进入了DMA7的中断?
有遇见过相同的问题吗?
此帖出自
小平头技术问答
最好把整个程序发上来.我也想看看:-)
void Initialize_NVIC (void)
{
NVIC.IPR6.W = 0x00000000;
SCB.VTOR.W = (unsigned long)0x8000000; // set the vectortable in the FLASH
SCB.AIRCR.W = (unsigned long)0x05FA0400; // ((u32)0x700) 0 bits for pre-emption priority , 4 bits for subpriority
// ((u32)0x600) 1 bits for pre-emption priority , 3 bits for subpriority
// ((u32)0x500) 2 bits for pre-emption priority , 2 bits for subpriority
// ((u32)0x400) 3 bits for pre-emption priority , 1 bits for subpriority
// ((u32)0x300) 4 bits for pre-emption priority , 0 bits for subpriority
NVIC.IPR11.B.EXTI15_10 |= 0x80; // set EXTI15_10 is the fifth interrupts Z相
NVIC.IPR10.W |= (unsigned long)0x400000; // set USART2 is the thired interrupt
NVIC.IPR8.W |= (unsigned long)0x600000; // set TIM4 is the fourth interrupt PWM波
NVIC.IPR5.W |= (unsigned long)0x2000; // set DMA1_CHANNEL7 is the second interrupt
SCB.SHPR3.W |= (unsigned long)0x00; // set SYSTICK is the first interrupt
NVIC.ISER1.W |= (unsigned long)0x48020000; // enable the TIM1CC & TIM4 & DMA1_CH7 interrupt
NVIC.ISER2.W |= (unsigned long)0x100; // enable the EXTI15_10 interrupt
NVIC.ISER2.W |= (unsigned long)0x40; // enable the USART2 interrupt
}
{
USART2.BRR.B.DIV_Fraction = 9; // 波特率: 115200
USART2.BRR.B.DIV_Mantissa = 19;
USART2.CR1.B.M = 0; // 1个起始位,8个数据位,n个停止位
USART2.CR1.B.PCE = 0; // 奇偶校验被禁止
USART2.CR2.B.STOP = 0; // 1个停止位
USART2.CR2.B.CLKEN = 0; // SCLK引脚被禁止
USART2.CR3.B.RTSE = 0; // RTS硬件流控制被禁止
USART2.CR3.B.CTSE = 0; // CTS硬件流控制被禁止
USART2.CR3.B.DMAT = 1; // DMA模式发送使能
USART2.CR3.B.DMAR = 0; // DMA模式接收禁止
USART2.CR1.B.RXNEIE = 1; // 当RXNE为1时,产生USART中断
USART2.CR1.B.TXEIE = 0;
USART2.CR1.B.TCIE = 0;
USART2.SR.B.TC = 1;
USART2.CR1.B.RE = 1; // 接受被使能
USART2.CR1.B.UE = 1; // USART模块被使能
}
这是USART2的配置函数
一周热门 更多>