Пример #1
0
/**
  * @brief  Automatic test switch to LSE clock from HSI and return to HSI
  * @caller auto_test
  * @param None
  * @retval None
  */
void test_LSE(void)
{
	
/* Switch the clock to LSE */
	
  LCD_GLASS_DisplayString("LSE");
  
  CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_1);
  CLK_LSEConfig(CLK_LSE_ON);
  delay_ms(LSE_DELAY);	
  
  if((CLK->ECKCR & CLK_ECKCR_LSERDY) == RESET)
  {
    LCD_GLASS_DisplayString("LSE");
    delay_ms(LSE_DELAY);
    if((CLK->ECKCR & CLK_ECKCR_LSERDY) == RESET)
    {
      LCD_GLASS_DisplayString("LSE");
      delay_ms(LSE_DELAY);
      if((CLK->ECKCR & CLK_ECKCR_LSERDY) == RESET)
      {			
        /* Switch the clock to HSI*/
        CLK_LSEConfig(CLK_LSE_OFF);
        CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_8);
        CLK_HSICmd(ENABLE);
        while (((CLK->ICKCR)& 0x02)!=0x02);
        CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
        CLK_SYSCLKSourceSwitchCmd(ENABLE);
        while (((CLK->SWCR)& 0x01)==0x01);
        
        while(1)
        {
          LCD_GLASS_ScrollSentence("LSE Not OK ",1,SCROLL_SPEED); //Press reset for exit
          KeyPressed = FALSE;
        }
      }
    }
  }

/* Wait flag LSE ready */
  while (!((CLK->ECKCR)& CLK_ECKCR_LSERDY));	

/* Switch in LSE clock */
  CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_LSE);
  CLK_SYSCLKSourceSwitchCmd(ENABLE);
  while (((CLK->SWCR)& 0x01)==0x01);
  
  LCD_GLASS_DisplayString("LSE OK");

/* Switch the clock to HSI */

  CLK_LSEConfig(CLK_LSE_OFF);
  CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_8);
  CLK_HSICmd(ENABLE);
  while (((CLK->ICKCR)& 0x02)!=0x02);
  CLK_SYSCLKSourceConfig(CLK_SYSCLKSource_HSI);
  CLK_SYSCLKSourceSwitchCmd(ENABLE);
  while (((CLK->SWCR)& 0x01)==0x01);
  delay_ms(100);
}
Пример #2
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  /* Enable LSE */
  CLK_LSEConfig(CLK_LSE_ON);
  /* Wait for LSE clock to be ready */
  while (CLK_GetFlagStatus(CLK_FLAG_LSERDY) == RESET);

  /* wait for 1 second for the LSE Stabilisation */
  LSE_StabTime();

  /* Select LSE (32.768 KHz) as RTC clock source */
  CLK_RTCClockConfig(CLK_RTCCLKSource_LSE, CLK_RTCCLKDiv_1);

  CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE);

  /* Calendar Configuration */
  Calendar_Init();

  /*RTC Tamper Configuration*/
  Tamper_Init();

  /* EvalBoard Configuration */
  EvalBoard_Init();

  Tamper_DelayShow(TampFilterIndex);

  while (1)
  {
    EnterSafeCode();
    Time_Show(LCD_LINE2, SHOW_POINT2);
    ExitSafeCode();
  }
}
Пример #3
0
/**
  * @brief This function initializes in Ultra Low Power mode, 
	*				disable the LCD, LSE and configures the unused IOs 
	*				in output push-pull
	* @caller main and ADC_Icc_Test
  * @param None
  * @retval None
  */ 
void Halt_Init(void)
{

/* Set STM8 in low power */
  PWR->CSR2 = 0x2;
  
  LCD_Cmd(DISABLE);

  /* To wait LCD disable */
  while ((LCD->CR3 & 0x40) != 0x00);
  
/* Set GPIO in low power*/	
  GPIO_LowPower_Config();
  
/* Stop RTC Source clock */
  CLK_RTCClockConfig(CLK_RTCCLKSource_Off, CLK_RTCCLKDiv_1);
  
  #ifdef USE_LSE
    CLK_LSEConfig(CLK_LSE_OFF);
    while ((CLK->ECKCR & 0x04) != 0x00);
  #else
    CLK_LSICmd(DISABLE);
    while ((CLK->ICKCR & 0x04) != 0x00);
  #endif
  
  /* Stop clock RTC and LCD */ 	
  CLK_PeripheralClockConfig(CLK_Peripheral_RTC, DISABLE);
  CLK_PeripheralClockConfig(CLK_Peripheral_LCD, DISABLE);
}
Пример #4
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  /* Enable LSE */
  CLK_LSEConfig(CLK_LSE_ON);
  /* Wait for LSE clock to be ready */
  while (CLK_GetFlagStatus(CLK_FLAG_LSERDY) == RESET);
  
  /* wait for 1 second for the LSE Stabilisation */
  Delay_Seconds(1);

  /* Select LSE (32.768 KHz) as RTC clock source */
  CLK_RTCClockConfig(CLK_RTCCLKSource_LSE, CLK_RTCCLKDiv_1);
  CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE);

  /*RTC Tamper Configuration*/
  Tamper_Init();

  /* Calendar Configuration */
  Calendar_Init();

  /* EvalBoard Configuration */
  EvalBoard_Init();

  /* RTC Time fields reset*/
  Time_Reset();

  /* RTC Time pause waiting for a press on SEL Key */
  Time_Pause();

  while (1)
  {
    EnterSafeCode();
    Time_Show(LCD_LINE2);
    ExitSafeCode();
  }
}