个位达人,我使用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
}
一周热门 更多>