/*********************************************/
/**本样例主要涉及串口主从机数据收发功能 ******/
/* 说明: **********/
/* 配置P35、P36为UART收发端口 **********/
/* 配置波特率38400bps **********/
/* 配置BaseTime1自动重载周期 **********/
/* 使能UART收发功能 **********/
/* 开发人员:TimShu QQ: 3386208645 *********/
/********************************************/
#include "uart.h"
#include "bt.h"
#include "gpio.h"
#define T1_PORT (3)
#define T1_PIN (3)
uint8_t u8TxData[10] = {0x99,0x88,0x77,0x66,0x55,0x44,0x33,0x22,0x11,0x00};
uint32_t u32RxData[10];
uint8_t u8TxCnt=0,u8RxCnt=0;
void SysTick_Handler(void)
{
static uint8_t u8val = 0;
Gpio_SetIO(T1_PORT, T1_PIN, u8val);
u8val = !u8val;
}
void TxIntCallback(void)
{
Uart_SendData(UARTCH1, u8TxData[u8TxCnt]);
u8TxCnt++;
if(u8TxCnt>10)
u8TxCnt=0;
}
void RxIntCallback(void)
{
u32RxData[u8RxCnt++]=Uart_ReceiveData(UARTCH1);
if(u8RxCnt>9)
u8RxCnt=0;
}
void ErrIntCallback(void)
{
}
int32_t main(void)
{
uint16_t timer,i=0;
uint32_t pclk;
stc_clk_config_t stcCfg;
stc_uart_config_t stcConfig;
stc_uart_irq_cb_t stcUartIrqCb;
stc_uart_multimode_t stcMulti;
stc_uart_baud_config_t stcBaud;
stc_bt_config_t stcBtConfig;
en_uart_mmdorck_t enTb8;
DDL_ZERO_STRUCT(stcConfig);
DDL_ZERO_STRUCT(stcUartIrqCb);
DDL_ZERO_STRUCT(stcMulti);
DDL_ZERO_STRUCT(stcBaud);
DDL_ZERO_STRUCT(stcBtConfig);
stcCfg.enClkSrc = ClkXTH;
stcCfg.enHClkDiv = ClkDiv1;
stcCfg.enPClkDiv = ClkDiv1;
Clk_Init(&stcCfg);
Gpio_InitIOExt(3,5,GpioDirOut,TRUE,FALSE,FALSE,FALSE);
Gpio_InitIOExt(3,6,GpioDirOut,TRUE,FALSE,FALSE,FALSE);
Gpio_SetIO(3,5,1);
Gpio_SetIO(3,6,1);
Gpio_SetFunc_UART1TX_P35();
Gpio_SetFunc_UART1RX_P36();
Clk_SetPeripheralGate(ClkPeripheralBt,TRUE);
Clk_SetPeripheralGate(ClkPeripheralUart1,TRUE);
stcUartIrqCb.pfnRxIrqCb = RxIntCallback;
stcUartIrqCb.pfnTxIrqCb = TxIntCallback;
stcUartIrqCb.pfnRxErrIrqCb = ErrIntCallback;
stcConfig.pstcIrqCb = &stcUartIrqCb;
stcConfig.bTouchNvic = TRUE;
stcConfig.enRunMode = UartMode3;
stcMulti.enMulti_mode = UartMulti;
enTb8 = AddrOrOdd;
Uart_SetMMDOrCk(UARTCH1,enTb8);
stcConfig.pstcMultiMode = &stcMulti;
stcBaud.u8Dbaud = 0u;
stcBaud.u32Baud = 38400u;
stcBaud.u8Mode = UartMode3;
pclk = Clk_GetPClkFreq();
timer=Uart_SetBaudRate(UARTCH1,pclk,&stcBaud);
stcBtConfig.enMD = BtMode2;
stcBtConfig.enCT = BtTimer;
Bt_Init(TIM1, &stcBtConfig);
Bt_ARRSet(TIM1,timer);
Bt_Cnt16Set(TIM1,timer);
Bt_Run(TIM1);
Uart_Init(UARTCH1, &stcConfig);
Uart_ClrStatus(UARTCH1,UartTxEmpty);
Uart_EnableFunc(UARTCH1,UartRx);
Uart_SendData(UARTCH1,0xC0);
while(0 == Uart_GetStatus(UARTCH1,UartTxEmpty));
enTb8 = DataOrEven;
Uart_SetMMDOrCk(UARTCH1,enTb8);
Uart_ClrStatus(UARTCH1,UartTxEmpty);
while(i<10)
{
Uart_SendData(UARTCH1,u8TxData[i]);
while(0 == Uart_GetStatus(UARTCH1,UartTxEmpty));
Uart_ClrStatus(UARTCH1,UartTxEmpty);
i++;
}
while(1);
}
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
|