因為沒裝置外部的32.768K震盪器
以下是設置的程式碼CLOCK設置
/* Unlock protected registers */
SYS_UnlockReg();
/* Enable clock source */
CLK_EnableXtalRC(CLK_PWRCON_OSC10K_EN_Msk|CLK_PWRCON_OSC22M_EN_Msk|CLK_PWRCON_XTL12M_EN_Msk);
/* Waiting for clock source ready */
CLK_WaitClockReady(CLK_CLKSTATUS_OSC10K_STB_Msk|CLK_CLKSTATUS_OSC22M_STB_Msk|CLK_CLKSTATUS_XTL12M_STB_Msk);
/* Disable PLL first to avoid unstable when setting PLL */
CLK_DisablePLL();
/* Set PLL frequency */
CLK->PLLCON = (CLK->PLLCON & ~(0x000FFFFFul)) | 0x00004016ul;
/* Waiting for PLL ready */
CLK_WaitClockReady(CLK_CLKSTATUS_PLL_STB_Msk);
/* If the defines do not exist in your project, please refer to the related clk.h in the Header folder appended to the tool package. */
/* Set HCLK clock */
CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_PLL, CLK_CLKDIV_HCLK(1));
/* Enable IP clock */
CLK_EnableModuleClock(ADC_MODULE);
CLK_EnableModuleClock(CAN0_MODULE);
CLK_EnableModuleClock(I2C0_MODULE);
CLK_EnableModuleClock(PWM45_MODULE);
//CLK_EnableModuleClock(RTC_MODULE);
CLK_EnableModuleClock(SPI0_MODULE);
CLK_EnableModuleClock(UART0_MODULE);
CLK_EnableModuleClock(PDMA_MODULE);
CLK_EnableModuleClock(TMR0_MODULE);
CLK_EnableModuleClock(TMR3_MODULE);
CLK_EnableModuleClock(WDT_MODULE);
// CLK_EnableModuleClock(WWDT_MODULE);
//CLK_EnableCKO(CLK_CLKSEL2_FRQDIV_S_HCLK, 11, 0);
//CLK->FRQDIV = CLK->FRQDIV & ~CLK_FRQDIV_CLKO_1HZ_EN_Msk;
CLK_SetModuleClock(RTC_MODULE, CLK_CLKSEL2_RTC_SEL_10K_LIRC, MODULE_NoMsk);
CLK_EnableModuleClock(RTC_MODULE);
/* Set IP clock */
CLK_SetModuleClock(ADC_MODULE, CLK_CLKSEL1_ADC_S_HCLK, CLK_CLKDIV_ADC(10));
CLK_SetModuleClock(PWM45_MODULE, CLK_CLKSEL2_PWM45_S_HCLK|CLK_CLKSEL2_PWM45_EXT_HCLK, MODULE_NoMsk);
//CLK_SetModuleClock(RTC_MODULE, CLK_CLKSEL2_RTC_SEL_10K_LIRC, MODULE_NoMsk);
CLK_SetModuleClock(SPI0_MODULE, CLK_CLKSEL1_SPI0_S_HCLK, MODULE_NoMsk);
//CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_CLKDIV_UART(1))
CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_HIRC, CLK_CLKDIV_UART(1));
CLK_SetModuleClock(TMR0_MODULE, CLK_CLKSEL1_TMR0_S_HXT, 0);
CLK_SetModuleClock(TMR3_MODULE, CLK_CLKSEL1_TMR3_S_LIRC, 0);
CLK_SetModuleClock(WDT_MODULE, CLK_CLKSEL1_WDT_S_HCLK_DIV2048, MODULE_NoMsk);
功能設置
void RTC_INIT(void)
{
/* Open RTC and start counting */
sWriteRTC.u32Year = DATABUFF[293];
sWriteRTC.u32Month = DATABUFF[294];
sWriteRTC.u32Day = DATABUFF[295];
sWriteRTC.u32DayOfWeek = DATABUFF[299];
sWriteRTC.u32Hour = DATABUFF[296];
sWriteRTC.u32Minute = DATABUFF[297];
sWriteRTC.u32Second = DATABUFF[298];
sWriteRTC.u32TimeScale = RTC_CLOCK_24;
RTC_Open(&sWriteRTC);
//DATABUFF是自行宣告的資料陣列,透過RS485寫入資料
}
void RTC_Read(void)
{
RTC_GetDateAndTime(&sReadRTC);
DATABUFF[293] = sReadRTC.u32Year;
DATABUFF[294] = sReadRTC.u32Month;
DATABUFF[295] = sReadRTC.u32Day;
DATABUFF[299] = sReadRTC.u32DayOfWeek;
DATABUFF[296] = sReadRTC.u32Hour;
DATABUFF[297] = sReadRTC.u32Minute;
DATABUFF[298] = sReadRTC.u32Second;
//DATABUFF是自行宣告的資料陣列,透過RS485讀取資料
}
在開機後 透過外部寫入時間
之後就一直讀取資料
發生一個現象
RTC讀取出來的秒數 每增加1
現實的秒數大約 3.X秒
是不適從32768改成10000是需要額外設定甚麼的嗎?
各位大大有碰過類似的問題嗎?
謝謝
|