很多时候我们都是通过串口来打印调试信息,特别是调试BLE时,因为如果在调试BLE设断点,设了断点之后,此时BLE就无法实时握手,就会断开连接;因此,用串口打印调试信息还是相当方便的。同时,当以后在使用透传时也是需要串口来与Psoc BLE通讯的,这里就以实现Psoc BLE的UART接收中断为例;
至此,UART组件已经配置完成了,编译下工程,接下来就要开始组织代码编写了。
CY_ISR(UART_SCB_IRQ_Interrupt) { #ifdef UART_SCB_IRQ_INTERRUPT_INTERRUPT_CALLBACK UART_SCB_IRQ_Interrupt_InterruptCallback(); #endif /* UART_SCB_IRQ_INTERRUPT_INTERRUPT_CALLBACK */ /* Place your Interrupt code here. */ /* `#START UART_SCB_IRQ_Interrupt` */ if(UART_GetRxInterruptSourceMasked()&UART_INTR_RX_NOT_EMPTY)//判断接收中断的类型 { uint32 ReceviceData=0; ReceviceData=UART_SpiUartReadRxData();//读取串口接收缓冲区的数据 // printf("%c",(uint8_t)ReceviceData); UART_UartPutChar((uint8_t)ReceviceData);//输出接收到的串口数据 } UART_SpiUartClearRxBuffer();//清除串口接收缓冲区 UART_ClearRxInterruptSource(UART_INTR_RX_NOT_EMPTY);//清除串口接收中断标志位,这个很重要如果没有清除的话会无限进入串口接收中断函数即UART_SCB_IRQ_Interrupt函数 /* `#END` */ }
int main() { /* Place your initialization/startup code here (e.g. MyInst_Start()) */ CyGlobalIntEnable; /* Enable global interrupts. */ UART_Start();//使能串口 UART_SCB_IRQ_Start();//使能中断 printf("UART Demo!\r\n"); // UART_SpiUartPutArray("Helon Test\r\n",sizeof("Helon Test\r\n")); for(;;) { /* Place your application code here. */ } }
CY_ISR(MY_UART_SCB_IRQ_Interrupt) { //这里增加对接收到的串口数据进行处理的代码 }