版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/kimiyang123/article/details/85853226
1.硬件模块搭建
对项目的*.cysch文件中添加UART(SCB mode)模块。
双击模块模型,并对其按如下设置,
- uart选择External模式,使用外部中断组件来获取中断信号
- 在PSoC Crestor右侧的System部件中选择 Interrupt,并将其更名为isr_uart
中断模式选择为 电平触发模式 LEVEL
2.程序设计
- 在主函数中添加如下代码
int main(void)
{
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
LED_R_Write(1); //led灯关闭
UART_1_Start(); //启动串口
UART_1_UartPutString("hello Uart\r\n"); //串口发送字符串
isr_uart_Start(); //启动中断模块
CyGlobalIntEnable; /* Enable global interrupts. */
for(;;)
{
/* Place your application code here. */
}
}
- 按下图找到 isr 中断程序句柄函数
CY_ISR(isr_uart_Interrupt)
{
#ifdef isr_uart_INTERRUPT_INTERRUPT_CALLBACK
isr_uart_Interrupt_InterruptCallback();
#endif /* isr_uart_INTERRUPT_INTERRUPT_CALLBACK */
/* Place your Interrupt code here. */
/* `#START isr_uart_Interrupt` */
//清除 RX_NOT_EMPTY 中断标志位
UART_1_ClearRxInterruptSource(UART_1_INTR_RX_NOT_EMPTY);
//将接收到的数据发回 回显
UART_1_UartPutChar(UART_1_UartGetChar());
/* `#END` */
}
3. 串口效果
后记
另外,用Uart内部[Internal]中断方式,即可不需要添加 Interrupt 组件。