本帖最后由 qweasda 于 2024-12-9 16:51 编辑
基本按照例程写的 ,只把模式三改成了模式一,是还需要改其他地方的配置么
void LPRxIntCallback(void)
{
u8RxData[1]=M0P_LPUART->SBUF;
u8LpRx** = 1;
}
void LPErrIntCallback(void)
{
}
void LPUART_Init(void)
{
uint16_t u16timer = 0;
uint32_t u32sclk = 0;
stc_lpuart_config_t stcConfig;
stc_lpuart_irq_cb_t stcLPUartIrqCb;
stc_lpuart_multimode_t stcMulti;
stc_lpuart_sclk_sel_t stcLpuart_clk;
stc_lpuart_mode_t stcRunMode;
stc_lpuart_baud_config_t stcBaud;
stc_bt_config_t stcBtConfig;
DDL_ZERO_STRUCT(stcConfig);
DDL_ZERO_STRUCT(stcLPUartIrqCb);
DDL_ZERO_STRUCT(stcMulti);
DDL_ZERO_STRUCT(stcBtConfig);
Clk_SetPeripheralGate(ClkPeripheralLpUart,TRUE);
Clk_SetPeripheralGate(ClkPeripheralBt,TRUE);
Gpio_InitIOExt(2,5,GpioDirOut,TRUE,FALSE,FALSE,FALSE);
Gpio_InitIOExt(2,6,GpioDirOut,TRUE,FALSE,FALSE,FALSE);
Gpio_SetFunc_UART2RX_P25();
Gpio_SetFunc_UART2TX_P26();
stcLpuart_clk.enSclk_sel = LPUart_Pclk;
stcLpuart_clk.enSclk_Prs = LPUartDiv1;
stcConfig.pstcLpuart_clk = &stcLpuart_clk;
stcRunMode.enLpMode = LPUartNoLPMode;
stcRunMode.enMode = LPUartMode1;
stcConfig.pstcRunMode = &stcRunMode;
stcLPUartIrqCb.pfnRxIrqCb = LPRxIntCallback;
stcLPUartIrqCb.pfnTxIrqCb = NULL;
stcLPUartIrqCb.pfnRxErrIrqCb = LPErrIntCallback;
stcConfig.pstcIrqCb = &stcLPUartIrqCb;
stcConfig.bTouchNvic = TRUE;
stcMulti.enMulti_mode = LPUartNormal;
stcConfig.pstcMultiMode = &stcMulti;
LPUart_EnableIrq(LPUartRxIrq);
LPUart_Init(&stcConfig);
if(LPUart_Pclk == stcLpuart_clk.enSclk_sel)
u32sclk = Clk_GetPClkFreq();
else if(LPUart_Rcl == stcLpuart_clk.enSclk_sel)
u32sclk = 38400;
else
u32sclk = 32768;
stcBaud.u32Baud = 9600;
stcBaud.bDbaud = 0;
stcBaud.u8LpMode = LPUartNoLPMode;
stcBaud.u8Mode = LPUartMode1;
u16timer = LPUart_SetBaudRate(u32sclk,stcLpuart_clk.enSclk_Prs,&stcBaud);
stcBtConfig.enMD = BtMode2;
stcBtConfig.enCT = BtTimer;
stcBtConfig.enTog = BtTogEnable;
Bt_Init(TIM2, &stcBtConfig);
Bt_ARRSet(TIM2,u16timer);
Bt_Cnt16Set(TIM2,u16timer);
Bt_Run(TIM2);
LPUart_EnableFunc(LPUartRx);
}
主函数写的这一段,串口1是可以正常收发数据的
if(u8LpRx**)
{
Gpio_SetIO(0,2,led_flagR);
Uart_SendData(UARTCH1,u8RxData[0]);
Uart_SendData(UARTCH1,u8RxData[1]);
} |