1. 已经将uart0和timer1的时钟源设为外部晶振HXT,为何关闭内部22M HIRC后uart0和timer1不能工作
当我把内部的22M HIRC关掉后,timer1就产生不了中断了,uart0也不能收发数据了,我已经将时钟源切换到HXT了也不行。
我的时钟初始化程序如下:
void SYS_Init(void)
{
//---------------------------------------------------------------------------------------------------------
// Init System Clock
//---------------------------------------------------------------------------------------------------------
// Enable Internal RC 22.1184MHz clock
CLK_EnableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);
// Waiting for Internal RC clock ready
CLK_WaitClockReady(CLK_CLKSTATUS_OSC22M_STB_Msk);
// Switch HCLK clock source to Internal RC and HCLK source divide 1
CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));
// Enable external XTAL 12MHz clock
CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk);
// Waiting for external XTAL clock ready
CLK_WaitClockReady(CLK_CLKSTATUS_XTL12M_STB_Msk);
//================================== 新增加 ==============================
// Switch HCLK clock source to Internal RC and HCLK source divide 1
CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HXT, CLK_CLKDIV_HCLK(1));
// Disable Internal RC 22.1184MHz clock
CLK_DisableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);
//========================================================================
// Set core clock as PLL_CLOCK from PLL
CLK_SetCoreClock(PLL_CLOCK);
// Enable UART module clock
CLK_EnableModuleClock(UART0_MODULE);
// Select UART module clock source
//CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_PLL, CLK_CLKDIV_UART(1));
CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_CLKDIV_UART(1));
// Enable TMR1 module clock
CLK_EnableModuleClock(TMR1_MODULE);
/* TMR1 clock source */
//CLK->CLKSEL1 |= CLK_CLKSEL1_TMR1_S_HCLK;
CLK->CLKSEL1 |= CLK_CLKSEL1_TMR1_S_HXT;
/* Update System Core Clock */
/* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
SystemCoreClockUpdate();
//---------------------------------------------------------------------------------------------------------
// Init I/O Multi-function
//---------------------------------------------------------------------------------------------------------
// Set P3 multi-function pins for UART0 RXD and TXD
SYS->P3_MFP &= ~(SYS_MFP_P30_Msk | SYS_MFP_P31_Msk);
SYS->P3_MFP |= (SYS_MFP_P30_RXD0 | SYS_MFP_P31_TXD0);
}
上述程序中,我只要将
// Disable Internal RC 22.1184MHz clock
CLK_DisableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);
这条语句注释掉(即不关闭HIRC),timer1和uart0就可以正常工作了,不知道这是什么原因
2. 掉电后静态电流仍为10mA,正常应该是几微安才对
进入掉电模式时的程序如下:
printf("Enter to Power-Down ......\n");
UART_WAIT_TX_EMPTY(UART0);
UART0_Close();
TMR1_Close();
// Disable Internal RC 22.1184MHz clock
CLK_DisableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);
// Disable external XTAL 12MHz clock
CLK_DisableXtalRC(CLK_PWRCON_XTL12M_EN_Msk);
// Update System Core Clock
// User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically.
SystemCoreClockUpdate();
SCB->SCR = 4;
CLK->PWRCON = (CLK->PWRCON & ~(CLK_PWRCON_PWR_DOWN_EN_Msk | CLK_PWRCON_PD_WAIT_CPU_Msk)) |
CLK_PWRCON_PD_WAIT_CPU_Msk | CLK_PWRCON_PD_WU_INT_EN_Msk;
CLK->PWRCON |= CLK_PWRCON_PWR_DOWN_EN_Msk;
__WFI();
|