void TxIntCallback(void)
{
// u8TxCnt++;
// if(u8TxCnt<=1)
// M0P_UART1->SBUF = u8TxData[1];
//
}
void RxIntCallback(void)
{
uint8_t Res;
//Uart_ClrStatus(UARTCH0,UartRC);
//Res = Uart_ReceiveData(UARTCH0); //鎺ユ敹鏁版嵁瀛楄妭
//MC30UART_RX_Buffer[MC30_Rx_Index++]=Res;
// Uart_DisableIrq(UARTCH0,UartRxIrq);
// Uart_SendData(UARTCH0, Res);
// Uart_EnableIrq(UARTCH0,UartRxIrq);
}
void ErrIntCallback(void)
{
}
void PErrIntCallBack(void)
{
}
void CtsIntCallBack(void)
{
}
void Bsp_Uart_Init(M0P_UART_TypeDef* UARTx , uint32_t bound)
{
App_PortInit(UARTx);
App_UartCfg(UARTx , bound);
}
//涓插彛寮曡剼閰嶇疆
void App_PortInit(M0P_UART_TypeDef* UARTx)
{
stc_gpio_config_t stcGpioCfg;
DDL_ZERO_STRUCT(stcGpioCfg);
Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio,TRUE); //浣胯兘GPIO妯″潡鏃堕挓
if(UARTx == M0P_UART1)
{
///<TX
stcGpioCfg.enDir = GpioDirOut;
Gpio_Init(GpioPortA, GpioPin2, &stcGpioCfg);
Gpio_SetAfMode(GpioPortA, GpioPin2, GpioAf1); //閰嶇疆PA02 绔?彛涓篣RART1_TX
///<RX
stcGpioCfg.enDir = GpioDirIn;
Gpio_Init(GpioPortA, GpioPin3, &stcGpioCfg);
Gpio_SetAfMode(GpioPortA, GpioPin3, GpioAf1); //閰嶇疆PA03 绔?彛涓篣RART1_RX
}
if(UARTx == M0P_UART0)
{
///<TX
stcGpioCfg.enDir = GpioDirOut;
Gpio_Init(GpioPortA, GpioPin9, &stcGpioCfg);
Gpio_SetAfMode(GpioPortA, GpioPin9, GpioAf1); //閰嶇疆PA02 绔?彛涓篣RART1_TX
///<RX
stcGpioCfg.enDir = GpioDirIn;
Gpio_Init(GpioPortA, GpioPin10, &stcGpioCfg);
Gpio_SetAfMode(GpioPortA, GpioPin10, GpioAf1); //閰嶇疆PA03 绔?彛涓篣RART1_RX
}
}
//涓插彛閰嶇疆
void App_UartCfg(M0P_UART_TypeDef* UARTx , uint32_t bound)
{
uint16_t u16Scnt = 0;
stc_uart_config_t stcConfig;
stc_uart_irq_cb_t stcUartIrqCb;
stc_uart_multimode_t stcMulti;
stc_uart_baud_t stcBaud;
en_uart_mmdorck_t enTb8;
DDL_ZERO_STRUCT(stcConfig);
DDL_ZERO_STRUCT(stcUartIrqCb);
DDL_ZERO_STRUCT(stcMulti);
stcUartIrqCb.pfnRxIrqCb = RxIntCallback;//中断入口地址
stcUartIrqCb.pfnTxIrqCb = TxIntCallback;
stcUartIrqCb.pfnRxFEIrqCb = ErrIntCallback;
stcUartIrqCb.pfnPEIrqCb = PErrIntCallBack;
stcUartIrqCb.pfnCtsIrqCb = CtsIntCallBack;
stcConfig.pstcIrqCb = &stcUartIrqCb;
stcConfig.bTouchNvic = TRUE;
if(TRUE == stcConfig.bTouchNvic)
{
EnableNvic(UART0_IRQn,IrqLevel3,TRUE);
}
stcConfig.enRunMode = UartMode3;//模式3
stcConfig.enStopBit = Uart1bit;//1位停止位
stcMulti.enMulti_mode = UartNormal;//正常工作模式
Uart_SetClkDiv(UARTCH0,Uart8Or16Div);//采样分频
Uart_SetClkDiv(UARTCH1,Uart8Or16Div);//采样分频
stcBaud.u32Pclk = Sysctrl_GetPClkFreq();
stcBaud.enRunMode = UartMode3;
stcBaud.u32Baud = 9600;
if(UARTx == M0P_UART0)
{
Sysctrl_SetPeripheralGate(SysctrlPeripheralUart0,TRUE);
Uart_SetMultiMode(UARTCH0,&stcMulti);//多主机单独配置
Uart_SetMMDOrCk(UARTCH0,UartDataOrAddr);
Uart_Init(UARTCH0, &stcConfig);//串口初始化函数
u16Scnt = Uart_CalScnt(UARTCH0,&stcBaud);//波特率值计算
Uart_SetBaud(UARTCH0,u16Scnt);//波特率设置
Uart_ClrStatus(UARTCH0,UartRC);//清接收请求
Uart_ClrStatus(UARTCH0,UartTC);//清接收请求
//Uart_EnableIrq(UARTCH0,UartRxIrq);//
Uart_EnableFunc(UARTCH0,UartRx);//使能收发
Uart_EnableFunc(UARTCH0,UartTx);//使能收发
}
if(UARTx == M0P_UART1)
{
Sysctrl_SetPeripheralGate(SysctrlPeripheralUart1,TRUE);
Uart_SetMultiMode(UARTCH1,&stcMulti);//多主机单独配置
Uart_SetMMDOrCk(UARTCH1,UartDataOrAddr);
Uart_Init(UARTCH1, &stcConfig);//串口初始化函数
Uart_SetClkDiv(UARTCH1,Uart8Or16Div);//采样分频
u16Scnt = Uart_CalScnt(UARTCH1,&stcBaud);//波特率值计算
Uart_SetBaud(UARTCH1,u16Scnt);//波特率设置
Uart_ClrStatus(UARTCH1,UartRC);//清接收请求
Uart_EnableIrq(UARTCH1,UartRxIrq);//
Uart_EnableFunc(UARTCH1,UartRx);//使能收发
}
}
void UART_Send_Char(M0P_UART_TypeDef* uartx,uint8_t data)
{
if(uartx == M0P_UART0)
Uart_SendData(UARTCH0, data );
else
Uart_SendData(UARTCH1, data );
//Uart_SendDataIt(uartx, data);
}
查询方式可接收数据 |
|