关于华大HC32L110的LPUART配置,参考手册上说可以在低功耗模式下工作,我这边打开串口后睡眠一直很高大概100ua,但是屏蔽串口初始化就可以达到7ua左右,不知道串口配置这边有什么问题?
/***********************************Lpuart_config************************/
//RX
#define LUART_RX_PORT 2
#define LUART_RX_PIN 5
#define LUART_RX_MODE GpioDirOut
#define LUART_RX_PULLUP TRUE
#define LUART_RX_PULLDOWN FALSE
#define LUART_RX_ODR FALSE
#define LUART_RX_DRIVER FALSE
//Luart_clk_config
#define LUART_RX_SCLK_SEL LPUart_Rcl //LPUart_Rcl LPUart_Pclk
#define LUART_RX_SCLK_DIV LPUartDiv1
//Luart_mode_config //LPUartLPMode LPUartNoLPMode
#define LUART_RX_MODE_LP LPUartLPMode //低功耗模式(说明默认配置串口波特率:9600(由时钟决定的不可改变))
#define LUART_RXMODE LPUartMode1 //带奇偶校验功能(MODE1是不带奇偶检验功能)
//tx
#define LUART_TX_PORT 2
#define LUART_TX_PIN 6
#define LUART_TX_MODE GpioDirOut
#define LUART_TX_PULLUP TRUE
#define LUART_TX_PULLDOWN FALSE
#define LUART_TX_ODR FALSE
#define LUART_TX_DRIVER FALSE
//Luart_clk_config
//#define LUART_TX_SCLK_SEL LPUart_Pclk
//#define LUART_TX_SCLK_DIV LPUartDiv1
//Luart_mode_config
//#define LUART_TX_MODE_LP LPUartNoLPMode //低功耗模式(说明默认配置串口波特率:9600(由时钟决定的不可改变))
//#define LUART_TXMODE LPUartMode3 //带奇偶校验功能(MODE1是不带奇偶检验功能)
#define LUART_BAUD 9600
/***********************************************************************/
void lpuart_pwr_on(void)
{
uint16_t u16timer;
uint32_t u32sclk;
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(stcLpuart_clk);
DDL_ZERO_STRUCT(stcRunMode);
DDL_ZERO_STRUCT(stcBaud);
DDL_ZERO_STRUCT(stcBtConfig);
//(1)open peripheral clk
Clk_SetPeripheralGate(ClkPeripheralLpUart,TRUE);
Clk_SetPeripheralGate(ClkPeripheralBt,TRUE);
//(2)set IO
Gpio_InitIOExt(LUART_RX_PORT,LUART_RX_PIN,LUART_RX_MODE,LUART_RX_PULLUP,LUART_RX_PULLDOWN,LUART_RX_ODR,LUART_RX_DRIVER);
Gpio_InitIOExt(LUART_TX_PORT,LUART_TX_PIN,LUART_TX_MODE,LUART_TX_PULLUP,LUART_TX_PULLDOWN,LUART_TX_ODR,LUART_TX_DRIVER);
Gpio_SetFunc_UART2RX_P25();
Gpio_SetFunc_UART2TX_P26();
//(3)clk config
stcLpuart_clk.enSclk_Prs = LUART_RX_SCLK_DIV;
stcLpuart_clk.enSclk_sel = LUART_RX_SCLK_SEL;
stcConfig.pstcLpuart_clk = &stcLpuart_clk;
//(4)mode config
stcRunMode.enLpMode = LUART_RX_MODE_LP;
stcRunMode.enMode = LUART_RXMODE;
stcConfig.pstcRunMode = &stcRunMode;
//(5)interrupt function
stcLPUartIrqCb.pfnRxIrqCb = RxIntCallback;
stcLPUartIrqCb.pfnTxIrqCb = NULL;
stcLPUartIrqCb.pfnRxErrIrqCb = NULL;
stcConfig.pstcIrqCb = &stcLPUartIrqCb;
stcConfig.bTouchNvic = TRUE;
//(6)正常模式
stcMulti.enMulti_mode = LPUartNormal;
stcConfig.pstcMultiMode = &stcMulti;
LPUart_EnableFunc(LPUartRx);
M0P_LPUART->ISR_f.RI = 0;
LPUart_EnableIrq(LPUartRxIrq);
LPUart_Init(&stcConfig);
//(1)
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 = LUART_BAUD;
stcBaud.bDbaud = 0;
stcBaud.u8LpMode = LUART_RX_MODE_LP;
stcBaud.u8Mode = LUART_RXMODE;
LPUart_EnableIrq(LPUartRxIrq);
LPUart_EnableFunc(LPUartRx);
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);
}
我这边main函数是:
int main(void)
{
delay1ms(3000); //延时避免睡眠无法烧录。
Allgpio_Init();
Led_init_task();
key_init_task();
lpuart_pwr_on();
while(1)
{
keyL_scan();
Real_exe();
Mcu_Sleep();
}
}
|