Example #1
0
/**
  * @brief  Sets the RTC counter value.
  * @param  CounterValue: RTC counter new value.
  * @retval None
  */
void RTC_SetCounter(uint32_t CounterValue)
{ 
  RTC_EnterConfigMode();
  /* Set RTC COUNTER MSB word */
  RTC->CNTH = CounterValue >> 16;
  /* Set RTC COUNTER LSB word */
  RTC->CNTL = (CounterValue & RTC_LSB_MASK);
  RTC_ExitConfigMode();
}
Example #2
0
/**
  * @brief  Sets the RTC alarm value.
  * @param  AlarmValue: RTC alarm new value.
  * @retval None
  */
void RTC_SetAlarm(uint32_t AlarmValue)
{  
  RTC_EnterConfigMode();
  /* Set the ALARM MSB word */
  RTC->ALRH = AlarmValue >> 16;
  /* Set the ALARM LSB word */
  RTC->ALRL = (AlarmValue & RTC_LSB_MASK);
  RTC_ExitConfigMode();
}
Example #3
0
/**
  * @簡述  設置 RTC 計數器值.
  * @參數  CounterValue: RTC 計數器的新值.
  * @返回  沒有
  */
void RTC_SetCounter(uint32_t CounterValue)
{ 
  RTC_EnterConfigMode();
  /* 設置 RTC 計數器高位字 */
  RTC->CNTH = CounterValue >> 16;
  /* 設置 RTC 計數器低位字 */
  RTC->CNTL = (CounterValue & RTC_LSB_Mask);
  RTC_ExitConfigMode();
}
Example #4
0
/**
  * @簡述  設置 RTC 報警寄存器的值.
  * @參數  AlarmValue: RTC 報警寄存器的新值.
  * @返回  沒有
  */
void RTC_SetAlarm(uint32_t AlarmValue)
{  
  RTC_EnterConfigMode();
  /* 設置報警寄存器高位字 */
  RTC->ALRH = AlarmValue >> 16;
  /* 設置報警寄存器低位字 */
  RTC->ALRL = (AlarmValue & RTC_LSB_Mask);
  RTC_ExitConfigMode();
}
/*******************************************************************************
* Function Name  : RTC_SetAlarm
* Description    : Sets the RTC alarm value.
* Input          : - AlarmValue: RTC alarm new value.
* Output         : None
* Return         : None
*******************************************************************************/
void RTC_SetAlarm(u32 AlarmValue)
{  
  RTC_EnterConfigMode();

  /* Set the ALARM MSB word */
  RTC->ALRH = (AlarmValue & RTC_MSB_Mask) >> 16;
  /* Set the ALARM LSB word */
  RTC->ALRL = (AlarmValue & RTC_LSB_Mask);

  RTC_ExitConfigMode();
}
/*******************************************************************************
* Function Name  : RTC_SetCounter
* Description    : Sets the RTC counter value.
* Input          : - CounterValue: RTC counter new value.
* Output         : None
* Return         : None
*******************************************************************************/
void RTC_SetCounter(u32 CounterValue)
{ 
  RTC_EnterConfigMode();

  /* Set RTC COUNTER MSB word */
  RTC->CNTH = (CounterValue & RTC_MSB_Mask) >> 16;
  /* Set RTC COUNTER LSB word */
  RTC->CNTL = (CounterValue & RTC_LSB_Mask);

  RTC_ExitConfigMode();
}
Example #7
0
/**
  * @brief  Sets the RTC alarm value.
  * @param AlarmValue: RTC alarm new value.
  * @retval : None
  */
void RTC_SetAlarm(uint32_t AlarmValue)
{  
 /* Set the CNF flag to enter in the Configuration Mode */
  RTC_EnterConfigMode();
  /* Set the ALARM MSB word */
  RTC->ALRH = AlarmValue >> 16;
  /* Set the ALARM LSB word */
  RTC->ALRL = (AlarmValue & RTC_LSB_MASK);
  /* Reset the CNF flag to exit from the Configuration Mode */
  RTC_ExitConfigMode();
}
Example #8
0
/*******************************************************************************
* 函数名称: RTC_SetCounter
* 功能描述: 设置RTC计数器值.
* 输入参数: CounterValue:RTC计数新值.
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void RTC_SetCounter(u32 CounterValue)
{ 
  RTC_EnterConfigMode();

  /* Set RTC COUNTER MSB word [设置RTC计数器高半字节]*/
  RTC->CNTH = CounterValue >> 16;
  /* Set RTC COUNTER LSB word [设置RTC计数器低半字节]*/
  RTC->CNTL = (CounterValue & RTC_LSB_Mask);

  RTC_ExitConfigMode();
}
/**
 * @brief  Sets the RTC prescaler value.
 * @param  PrescalerValue: RTC prescaler new value.
 * @retval None
 */
void RTC_SetPrescaler(uint32_t PrescalerValue) {
	/* Check the parameters */
	assert_param(IS_RTC_PRESCALER(PrescalerValue));

	RTC_EnterConfigMode();
	/* Set RTC PRESCALER MSB word */RTC ->PRLH = (PrescalerValue
			& PRLH_MSB_MASK ) >> 16;
	/* Set RTC PRESCALER LSB word */RTC ->PRLL = (PrescalerValue
			& RTC_LSB_MASK );
	RTC_ExitConfigMode();
}
Example #10
0
/**
  * @簡述  設置 RTC 預分頻裝在寄存器的值.
  * @參數  PrescalerValue: RTC 預分頻裝在寄存器的新值.
  * @返回  沒有
  */
void RTC_SetPrescaler(uint32_t PrescalerValue)
{
  /* 檢查參數 */
  assert_param(IS_RTC_PRESCALER(PrescalerValue));
  
  RTC_EnterConfigMode();
  /* 設置 RTC 預分頻裝在寄存器高位字 */
  RTC->PRLH = (PrescalerValue & PRLH_MSB_Mask) >> 16;
  /* 設置 RTC 預分頻裝在寄存器低位字 */
  RTC->PRLL = (PrescalerValue & RTC_LSB_Mask);
  RTC_ExitConfigMode();
}
Example #11
0
File: rtc.c Project: yzfcer/wind-os
/*
************************************************************
*	函数名称:	RTC_Init
*
*	函数功能:	RTC初始化
*
*	入口参数:	无
*
*	返回参数:	无
*
*	说明:		
************************************************************
*/
_Bool RTC_Init(void)
{
	
#if(USE_EXT_RCC == 1)
	unsigned char errCount = 0;
#endif

	RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); //使能PWR和BKP外设时钟   
	PWR_BackupAccessCmd(ENABLE); //使能后备寄存器访问
	
	BKP_DeInit();	//复位备份区域
#if(USE_EXT_RCC == 1)
	RCC_LSEConfig(RCC_LSE_ON);	//设置外部低速晶振(LSE),使用外设低速晶振
	while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET && errCount < 250)	//检查指定的RCC标志位设置与否,等待低速晶振就绪
	{
		errCount++;
		DelayMs(10);
	}
	if(errCount >= 250)
		return 1; //初始化时钟失败,晶振有问题
#endif
	
#if(USE_EXT_RCC == 1)
	RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); 		//设置RTC时钟(RTCCLK),选择LSE作为RTC时钟
#else
	RCC_RTCCLKConfig(RCC_RTCCLKSource_HSE_Div128);	//设置RTC时钟(HSE/128),选择HES作为RTC时钟
#endif
	RCC_RTCCLKCmd(ENABLE); //使能RTC时钟
	RTC_WaitForLastTask(); //等待最近一次对RTC寄存器的写操作完成
	RTC_WaitForSynchro(); //等待RTC寄存器同步
	
	RTC_ITConfig(RTC_IT_ALR, ENABLE); //使能RTC闹钟中断
	RTC_WaitForLastTask(); //等待最近一次对RTC寄存器的写操作完成
	
	RTC_EnterConfigMode(); //允许配置
#if(USE_EXT_RCC == 1)
	RTC_SetPrescaler(32767); //设置RTC预分频的值
#else
	RTC_SetPrescaler(HSE_VALUE / 128 - 1); //设置RTC预分频的值
#endif
	RTC_WaitForLastTask(); //等待最近一次对RTC寄存器的写操作完成
	
	RTC_SetCounter(0); //设置RTC计数器的值
	RTC_WaitForLastTask(); //等待最近一次对RTC寄存器的写操作完成
	
	RTC_ExitConfigMode(); //退出配置模式
	
	RTC_NVIC_Init();
	
	return 0;

}
/*******************************************************************************
* Function Name  : RTC_SetPrescaler
* Description    : Sets the RTC prescaler value.
* Input          : - PrescalerValue: RTC prescaler new value.
* Output         : None
* Return         : None
*******************************************************************************/
void RTC_SetPrescaler(u32 PrescalerValue)
{
  /* Check the parameters */
  assert(IS_RTC_PRESCALER(PrescalerValue));
  
  RTC_EnterConfigMode();

  /* Set RTC PRESCALER MSB word */
  RTC->PRLH = (PrescalerValue & PRLH_MSB_Mask) >> 0x10;
  /* Set RTC PRESCALER LSB word */
  RTC->PRLL = (PrescalerValue & RTC_LSB_Mask);

  RTC_ExitConfigMode();
}
Example #13
0
/*******************************************************************************
* 函数名称: RTC_SetPrescaler
* 功能描述: 获得RTC预分频数值.
* 输入参数: PrescalerValue:RTC预分频数新值.
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void RTC_SetPrescaler(u32 PrescalerValue)
{
  /* Check the parameters [检查参数]*/
  assert_param(IS_RTC_PRESCALER(PrescalerValue));
  
  RTC_EnterConfigMode();

  /* Set RTC PRESCALER MSB word [设置RTC分频器高半字节]*/
  RTC->PRLH = (PrescalerValue & PRLH_MSB_Mask) >> 16;
  /* Set RTC PRESCALER LSB word [设置RTC分频器低半字节]*/
  RTC->PRLL = (PrescalerValue & RTC_LSB_Mask);

  RTC_ExitConfigMode();
}
Example #14
0
uint8_t RTC_SetCounter(uint32_t CounterValue)
{ 
	uint32_t AlarmValue = CounterValue + RTC_FREQUENCY;
	RTC_EnterConfigMode();
	/* Set RTC COUNTER MSB word */
	RTC->CNTH = CounterValue >> 16;
	/* Set RTC COUNTER LSB word */
	RTC->CNTL = (CounterValue & RTC_LSB_MASK);
	/* Set the ALARM MSB word */
	RTC->ALRH = AlarmValue >> 16;
	/* Set the ALARM LSB word */
	RTC->ALRL = (AlarmValue & RTC_LSB_MASK);
	RTC_ExitConfigMode();
		return 0;
}
Example #15
0
uint08 RTC_Init(void)
{
    //检查是不是第一次配置时钟
    uint08 temp=0;

    if ( BKP_ReadBackupRegister(BKP_DR1) != 0x5050 )      //从指定的后备寄存器中读出数据:读出了与写入的指定数据不相乎
    {
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);    //使能PWR和BKP外设时钟   
        PWR_BackupAccessCmd(ENABLE);    //使能后备寄存器访问 
        BKP_DeInit();   //复位备份区域 	
        RCC_LSEConfig(RCC_LSE_ON);  //设置外部低速晶振(LSE),使用外设低速晶振
        while ( RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET && temp< 252) //检查指定的RCC标志位设置与否,等待低速晶振就绪
        {
            temp++;
            //delay_ms(10);
            //OSTimeDlyHMSM(0, 0, 0, 10); 
        }
        if ( temp>=250 )
        {
          return 1;//初始化时钟失败,晶振有问题	 
        }
        RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);     //设置RTC时钟(RTCCLK),选择LSE作为RTC时钟    
        RCC_RTCCLKCmd(ENABLE);  //使能RTC时钟  
        RTC_WaitForLastTask();  //等待最近一次对RTC寄存器的写操作完成
        RTC_WaitForSynchro();       //等待RTC寄存器同步  
        RTC_ITConfig(RTC_IT_SEC, ENABLE);       //使能RTC秒中断
        RTC_WaitForLastTask();  //等待最近一次对RTC寄存器的写操作完成
        RTC_EnterConfigMode();/// 允许配置	
        RTC_SetPrescaler(32767); //设置RTC预分频的值
        RTC_WaitForLastTask();  //等待最近一次对RTC寄存器的写操作完成
        RTC_Set(2009,12,2,10,0,55);  //设置时间	
        RTC_ExitConfigMode(); //退出配置模式  
        BKP_WriteBackupRegister(BKP_DR1, 0X5050);   //向指定的后备寄存器中写入用户程序数据
    }
    else//系统继续计时
    {

        RTC_WaitForSynchro();   //等待最近一次对RTC寄存器的写操作完成
        RTC_ITConfig(RTC_IT_SEC, ENABLE);   //使能RTC秒中断
        RTC_WaitForLastTask();  //等待最近一次对RTC寄存器的写操作完成
    }
    RTC_NVIC_Config();//RCT中断分组设置		    				     
    RTC_Get();//更新时间	
    return 0; //ok

}                           
Example #16
0
// init RTC
void rtc_init(void)
{
    uint16_t WaitForOscSource;
    
		/*RTC_NVIC Configuration */
    RTC_NVIC_Configuration();
	
    /*Enables the clock to Backup and power interface peripherals    */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP | RCC_APB1Periph_PWR,ENABLE);

    /*Allow access to Backup Registers*/
    PWR_BackupAccessCmd(ENABLE);
    if(BKP_ReadBackupRegister(BKP_DR1)== (uint16_t)(~CONFIGURATION_DONE))
    {
        /*Enables the clock to Backup and power interface peripherals    */
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP | RCC_APB1Periph_PWR,ENABLE);

        /* Backup Domain Reset */
        BKP_DeInit();
        systime.Month=DEFAULT_MONTH;
        systime.Day=DEFAULT_DAY;
        systime.Year=DEFAULT_YEAR;

        BKP_ModifyBackupRegister(BKP_DR3, (systime.Month << 8) | systime.Day);
        BKP_ModifyBackupRegister(BKP_DR5, systime.Year);
            
        /* Wait until last write operation on RTC registers has finished */
        RTC_WaitForLastTask();
        /* enter config mode */
        RTC_EnterConfigMode();
        /*Enable 32.768 kHz external oscillator */
        RCC_LSEConfig(RCC_LSE_ON);
        /* select clock source for RTC */
        RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
        /* RTC Enabled */
        RCC_RTCCLKCmd(ENABLE);
        /*Wait for RTC registers synchronisation */
        RTC_WaitForSynchro();
        RTC_WaitForLastTask();
        /* Setting RTC Interrupts-Seconds interrupt enabled */
        /* Enable the RTC Second */
        RTC_ITConfig(RTC_IT_SEC , ENABLE);
        /* Wait until last write operation on RTC registers has finished */
        RTC_WaitForLastTask();
        /* init prescale value*/
        RTC_SetPrescaler(32767);
        /* exit config mode */
        RTC_ExitConfigMode();

        /* Set default system time to 09 : 24 : 00 */
        SetTime(DEFAULT_HOURS,DEFAULT_MINUTES);
        BKP_ModifyBackupRegister(BKP_DR1, CONFIGURATION_DONE);
    }
    else
    {
        /* PWR and BKP clocks selection */
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
        for(WaitForOscSource=0;WaitForOscSource<5000;WaitForOscSource++);
        /* Wait until last write operation on RTC registers has finished */
        RTC_WaitForLastTask();
        /* Enable the RTC Second */
        RTC_ITConfig(RTC_IT_SEC, ENABLE);
        RTC_WaitForLastTask();
    }

    /* Check if how many days are elapsed in power down/Low Power Mode-
        Updates Date that many Times*/
    CheckForDaysElapsed();
    systime.Month = (uint8_t)(BKP_ReadBackupRegister(BKP_DR3) >> 8);
    systime.Day = (uint8_t)BKP_ReadBackupRegister(BKP_DR3);
    systime.Year = (uint8_t)BKP_ReadBackupRegister(BKP_DR5);
    
    BKP_RTCOutputConfig(BKP_RTCOutputSource_None);
}