此處附上接收中斷源碼
#ifdef _RAISONANCE_
void USART_RX_IRQHandler(void) interrupt 28
#endif
uint8_t cnt_USART ;
#ifdef _IAR_SYSTEMS_
#pragma vector=30
__interrupt void USART_RX_IRQHandler(void)
#endif
{
/* In order to detect unexpected events during development,
it is recommended to set a breakpoint on the following instruction.
*/
USART_ClearITPendingBit ();//清中斷標誌
if(!USART_GetFlagStatus (USART_FLAG_RXNE))//等待接收完畢
{
p_rxbuf[cnt_USART++] = USART_ReceiveData8(); //接收數據
if(cnt_USART == 0x0B)
cnt_USART = 0xFF ;
}
// USART_RendCmd(p_rxbuf); //接收11bytes串口指令
}
cnt_USART 爲全局變量,因爲每次接收每次只是接收1byte,因此,在主程序應該進行適當的延時來等待緩衝區的數據被讀取。
while(cnt_USART!=0xFF)
{
if(mark_1ms >100)
break;
}
在函數進行適當的延時進行等待,mark_1ms 此處是使用TIM2進行延時,也可以在主函數中進行空函數延時。