Topic : Wake up from Halt Mode.HOW?(STM8L101xx )

Forum : ST7/STM8

Original Post
Post Information Post
February 24, 2012 - 2:19pm
Guest

Hi,

I'm using stm8L101xx and when i use "halt();" function MCU enter in halt mode, but how mcu will wake up from halt mode i don't know.

I need to use external interrupt port B how can i write this code(C-Ride7)?

External interrupt port B supports to wake up from halt mode.

Can anybody help me pls?

Replies
Post Information Post
+1
0
-1
February 27, 2012 - 2:25pm
Guest

I wrote here answer of my question(with LCD and SPI application) good luck.

 /* Includes ------------------------------------------------------------------*/
 #include "stm8l10x.h"
 //#include "mono_lcd.h"
 
  
  #define LEDS_PORT (GPIOB)
  #define LED2_PIN  (GPIO_Pin_1)
  #define LED3_PIN  (GPIO_Pin_2)
  #define LED4_PIN  (GPIO_Pin_3)
  
  #define BUTTON_PORT (GPIOB)
  #define BUTTON_PIN  (GPIO_Pin_5)
  #define BUTTON_PIN2  (GPIO_Pin_6)
   
  uint32_t LSIMeasurment(void);
  void Delay(uint32_t nCount);
  

  void main(void)
  {
    int i;
    int j;
     
    /* Initialization of the clock */
    /* Clock divider to HSI/1 */
    CLK_MasterPrescalerConfig(CLK_MasterPrescaler_HSIDiv1);
                  
    /* Enable SPI clock */
    //CLK_PeripheralClockConfig(CLK_Peripheral_SPI, ENABLE);
    CLK_PeripheralClockConfig(CLK_Peripheral_TIM2, ENABLE);
    CLK_PeripheralClockConfig(CLK_Peripheral_AWU, ENABLE);
  
    /* Initialization of I/Os in Output Mode */
    GPIO_Init(LEDS_PORT, (LED2_PIN | LED3_PIN | LED4_PIN), GPIO_Mode_Out_PP_Low_Fast);
  
    /* Initialization of I/O in Input Mode with Interrupt */
    GPIO_Init(BUTTON_PORT, BUTTON_PIN, GPIO_Mode_In_FL_IT);
    GPIO_Init(BUTTON_PORT, BUTTON_PIN2, GPIO_Mode_In_FL_IT);                
  
    /* Initialization of the Interrupt sensitivity */
    
    EXTI_SetPinSensitivity(EXTI_Pin_5, EXTI_Trigger_Falling);
    EXTI_SetPinSensitivity(EXTI_Pin_6, EXTI_Trigger_Falling);
     /* Initialization of AWU */
     /* LSI calibration for accurate auto wake up time base*/
    
    AWU_LSICalibrationConfig(LSIMeasurment());
    AWU_Init(AWU_Timebase_No_IT);
    /* The delay corresponds to the time we will stay in Halt mode */
    
    //AWU_Init(AWU_Timebase_No_IT);
    /* Initialize SPI for LCD */
    //SPI_DeInit();
    //SPI_Init(SPI_FirstBit_MSB, SPI_BaudRatePrescaler_256, SPI_Mode_Master, SPI_CPOL_High, SPI_CPHA_2Edge, SPI_Direction_1Line_Tx, SPI_NSS_Soft);
  
    //SPI_Cmd(ENABLE);
  
    /* Initialize LCD */
    // LCD_Init();
  
    /* Clear LCD lines */ 
    // LCD_Clear();
  
    // LCD_PrintString(LCD_LINE1, ENABLE, DISABLE, "  Running...");
    // LCD_PrintString(LCD_LINE2, ENABLE, DISABLE, "   Press Key");
  
    /* Enable general interrupts */
    enableInterrupts();
  
    while (1)
    {
      
      
      /* Check button status */
   if ((GPIO_ReadInputData(GPIOB) &(GPIO_Pin_5)) == (uint8_t)0x00) /* Button is pressed */
      {
  
       
        /* LEDs toggle quickly */
        for (j = 0; j < 20; j++)
        {       
                GPIO_ToggleBits(LEDS_PORT, (LED2_PIN | LED3_PIN | LED4_PIN));
                Delay((uint32_t)10000);
        
        }
  
   
        halt(); /* Program halted */
 
      }
      
  if ((GPIO_ReadInputData(GPIOB) &(GPIO_Pin_6)) == (uint8_t)0x00)
  {
       GPIO_SetBits(LEDS_PORT,LED4_PIN);
       Delay((uint32_t)10000);
       GPIO_ResetBits(LEDS_PORT,LED4_PIN);
       Delay((uint32_t)60000);
       GPIO_SetBits(LEDS_PORT,LED3_PIN);
       Delay((uint32_t)10000);
       GPIO_ResetBits(LEDS_PORT,LED3_PIN);
       Delay((uint32_t)60000);
       GPIO_SetBits(LEDS_PORT,LED2_PIN);
       Delay((uint32_t)10000);
       GPIO_ResetBits(LEDS_PORT,LED2_PIN);
       Delay((uint32_t)60000);
       
       halt();
  }    /*
       // Toggle LEDs slowly 
       //GPIO_ToggleBits(LEDS_PORT, (LED2_PIN | LED3_PIN | LED4_PIN));
       //for (i = 0; i < 15; i++)
       //{
       // Delay((uint32_t)600000);
       //}
      } */
    }
  }

 uint32_t LSIMeasurment(void)
 {
 
   uint32_t lsi_freq_hz = 0x0;
   uint32_t fmaster = 0x0;
   uint16_t ICValue1 = 0x0;
   uint16_t ICValue2 = 0x0;
 
   /* Get master frequency */
   fmaster = CLK_GetClockFreq();
 
         /* Enable the LSI measurement: LSI clock connected to timer Input Capture 1 */
   AWU->CSR |= AWU_CSR_MSR;
 
   /* Capture only every 8 events!!! */
   TIM2_ICInit(  TIM2_Channel_1, TIM2_ICPolarity_Rising, TIM2_ICSelection_DirectTI, TIM2_ICPSC_Div8, 0x0);
 
   /* Enable TIM2 */
   TIM2_Cmd(ENABLE);
 
   /* wait a capture on cc1 */
   while ((TIM2->SR1 & (uint8_t)TIM2_FLAG_CC1) != TIM2_FLAG_CC1);
   /* Get CCR1 value*/
   ICValue1 = TIM2_GetCapture1();
   TIM2_ClearFlag(TIM2_FLAG_CC1);
 
   /* wait a capture on cc1 */
   while ((TIM2->SR1 & (uint8_t)TIM2_FLAG_CC1) != TIM2_FLAG_CC1);
   /* Get CCR1 value*/
   ICValue2 = TIM2_GetCapture1();
   TIM2_ClearFlag(TIM2_FLAG_CC1);
 
   /* Disable IC1 input capture */
   TIM2->CCER1 &= (uint8_t)(~TIM_CCER1_CC1E);
   /* Disable TIM2 */
   TIM2_Cmd(DISABLE);

   /* Compute LSI clock frequency */
   lsi_freq_hz = (8 * fmaster) / (ICValue2 - ICValue1);
 
         /* Disable the LSI measurement: LSI clock disconnected from timer Input Capture 1 */
   AWU->CSR &= (uint8_t)(~AWU_CSR_MSR);
   
   return (lsi_freq_hz);
 
 }
void Delay(uint32_t nCount)
{       //nCount=259000 => 1 second
        /* Decrement nCount value */
        while (nCount != 0)
        {
            nCount--;
        }
}