代码如下,是从官方例程改的,引脚换成了23,24,现象是串口能够发送,但是好像进不去
回调函数,里面的亮灯操作不会执行。
uint8_t u8RxData[2]={0x55,0x00};
uint8_t volatile u8Rx**=0;
uint8_t Check**=0;
void RxIntCallback(void)
{
u8RxData[1]=M0P_UART1->SBUF;
u8Rx** = 1;
// Uart_SendData(UARTCH1,u8RxData[0]);
Gpio_SetIO(0,2,FALSE);
}
void ErrIntCallback(void)
{
Uart_SendData(UARTCH1,0xaa);
}
void uart_init(void)
{
uint16_t timer=0;
uint32_t pclk=0;
stc_uart_config_t stc_uart_config; //uart 总体配置
stc_uart_irq_cb_t stc_uart_irq_cb; //uart发送接收中断处理函数接口
stc_uart_multimode_t stc_uart_multimode; //uart多主机模式及从机地址和地址掩码配置
stc_uart_baud_config_t stc_uart_baud_config; //uart 通道波特率配置
stc_bt_config_t stc_bt_config; //Timer 配置结构体定义
//重置结构体
DDL_ZERO_STRUCT(stc_uart_irq_cb);
DDL_ZERO_STRUCT(stc_uart_multimode);
DDL_ZERO_STRUCT(stc_uart_baud_config);
DDL_ZERO_STRUCT(stc_bt_config);
timer=0;
pclk=0;
Gpio_InitIOExt(2,3,GpioDirOut,FALSE, FALSE,FALSE,FALSE);//P35 输出 上拉 不下拉 不开漏 高驱动
Gpio_InitIOExt(2,4,GpioDirOut,FALSE, FALSE,FALSE,FALSE);//P35 输入 上拉 不下拉 不开漏 高驱动
// Gpio_SetFunc_UART1TX_P35();
// Gpio_SetFunc_UART1RX_P36();
Gpio_SetFunc_UART1TX_P23();
Gpio_SetFunc_UART1RX_P24();
Clk_SetPeripheralGate(ClkPeripheralBt,TRUE);//模式0/2可以不使能
Clk_SetPeripheralGate(ClkPeripheralUart1,TRUE);
stc_uart_irq_cb.pfnRxIrqCb = RxIntCallback; //接收中断回调
stc_uart_irq_cb.pfnTxIrqCb = NULL; //发送中断回调
stc_uart_irq_cb.pfnRxErrIrqCb = ErrIntCallback; //接收错误中断回调
stc_uart_config.pstcIrqCb = &stc_uart_irq_cb; //中断服务函数结构体
stc_uart_config.bTouchNvic = TRUE; //中断使能
stc_uart_config.enRunMode = UartMode1; //测试项,更改此处来转换4种模式测试
stc_uart_multimode.enMulti_mode = UartNormal; //测试项,更改此处来转换多主机模式,mode2/3才有多主机模式
stc_uart_config.pstcMultiMode = &stc_uart_multimode; //多机模式配置
stc_uart_baud_config.bDbaud = 0u;
stc_uart_baud_config.u32Baud = 9600u;
stc_uart_baud_config.u8Mode = UartMode1;
pclk = Clk_GetPClkFreq(); //获得外设时钟(PCLK)频率值
timer=Uart_SetBaudRate(UARTCH1,pclk,&stc_uart_baud_config);//UART通道波特率配置
stc_bt_config.enMD = BtMode2; //定时器工作模式自动重装载16位计数器
stc_bt_config.enCT = BtTimer; //定时器功能
Bt_Init(TIM1, &stc_bt_config); //调用basetimer1设置函数产生波特率
Bt_ARRSet(TIM1,timer); //重装载值配置
Bt_Cnt16Set(TIM1,timer); //16位计数器初始值设置
Bt_Run(TIM1);
Uart_Init(UARTCH1, &stc_uart_config); //通道初始化
Uart_EnableIrq(UARTCH1,UartRxIrq); //UART通信中断使能
Uart_ClrStatus(UARTCH1,UartRxFull); //UART通道通信状态清除
Uart_EnableFunc(UARTCH1,UartRx); //UART通道发送或接收使能设置
Uart_EnableFunc(UARTCH1,UartTx);
}
void LED_init(void)
{
//GPIO输出
Gpio_InitIOExt(0, 2, GpioDirOut, TRUE, FALSE, TRUE, FALSE);
Gpio_SetIO(0,2,TRUE);
}
int32_t main(void)
{
uart_init();
LED_init();
while(1)
{
Check** = 0;
// Gpio_SetIO(0,2,TRUE);
if(u8Rx**)
{
u8Rx** = 0;
// if(Uart_CheckEvenOrOdd(UARTCH1,Even,u8RxData[1])!=Ok)
// {
// Check** = 1;//奇偶校验出错
// }
// else
{
// Uart_SetTb8(UARTCH1,Even,u8RxData[0]);
Uart_SendData(UARTCH1,u8RxData[0]);
// Uart_SetTb8(UARTCH1,Even,u8RxData[1]);
Uart_SendData(UARTCH1,u8RxData[1]);
}
}
Uart_SendData(UARTCH1, u8RxData[1]);
delay1ms(1000);
// Gpio_SetIO(0,2,FALSE);
// delay1ms(1000);
}
} |