stm8s串口接收数据老是丢失字节,比如收一串字符,接收的数据偶尔会丢失一个字节。现在可以确定是串口溢出了,就是上一个数据还没有处理完成后一个数据就来了,因此只能舍弃。目前有一个1ms的定时器1和一个大约500ms的定时器2。目前猜测是定时器1抢占了串口中断,因为定时器1写了很多内容。现在想用中断优先级解决,想把串口接收的优先级调到最高,但是用库函数总是不成功!!
ITC_SetSoftwarePriority(ITC_IRQ_UART1_RX, ITC_PRIORITYLEVEL_3);
上面这段代码会让程序进入异常状态:
void ITC_SetSoftwarePriority(ITC_Irq_TypeDef IrqNum, ITC_PriorityLevel_TypeDef PriorityValue)//库函数
{
uint8_t Mask = 0;
uint8_t NewPriority = 0;
/* Check function parameters */
assert_param(IS_ITC_IRQ_OK((uint8_t)IrqNum));
assert_param(IS_ITC_PRIORITY_OK(PriorityValue));
/* Check if interrupts are disabled */
assert_param(IS_ITC_INTERRUPTS_DISABLED);
/* Define the mask corresponding to the bits position in the SPR register */
/* The mask is reversed in order to clear the 2 bits after more easily */
Mask = (uint8_t)(~(uint8_t)(0x03U << (((uint8_t)IrqNum % 4U) * 2U)));
/* Define the new priority to write */
NewPriority = (uint8_t)((uint8_t)(PriorityValue) << (((uint8_t)IrqNum % 4U) * 2U));
switch (IrqNum)
{...}
}
调试发现是进入了这句话: assert_param(IS_ITC_INTERRUPTS_DISABLED);
可以理解为判断此中断是否disable么?
要怎么写才能正常调用啊,如果调用成功,那么串口优先处理完是否会自动跳到timer1继续处理函数??
|