Skip to main content
Visitor II
April 16, 2021
Question

how can i implement UART wake up from halt mode ? please give me suggestion

  • April 16, 2021
  • 10 replies
  • 3097 views

I have development board of STM8L152R8. I want process like after uart interrupt comes controller should exit from halt mode . and after completing the routine it goes in halt mode again.

I didn't find example regarding this subject.

please help me to find the solution

thanks and regards

Deoyani

    This topic has been closed for replies.

    10 replies

    Visitor II
    April 20, 2021

    You cannot wake from HALT with the UART. See page 62 of the Datasheet. But you could try to use a GPIO in EXTI mode that is connected to the RXD of the UART.

    DJosh.0Author
    Visitor II
    April 21, 2021

    I have tried GPIO In EXTI mode that is connected to the RXD of UART but it is not working .

    can you give me suggestion how to demo code for Halt mode of STM8 I have seen the example code from peripheral library , but I am not understanding too much .

    can you give me any document or link to implement Halt mode and wake up from halt mode ?

    thanks and Regards

    Deoyani

    Visitor II
    April 21, 2021

    Here are some bits from an experiment I did with a STM8L151C8

    part of main:

    while (1)
    	{
    		PWR_UltraLowPowerCmd(ENABLE); //disables the VREFINT in halt
    		PWR_FastWakeUpCmd(ENABLE); //starts without VREFINT stable
    		CLK_HaltConfig(CLK_Halt_SlowWakeup, ENABLE); //do not keep CLK running in halt
    		
    		GPIO_Init(GPIOA, GPIO_Pin_All, GPIO_Mode_In_PU_No_IT); //all GPIO as input with pullup
    		GPIO_Init(GPIOB, GPIO_Pin_All, GPIO_Mode_In_PU_No_IT); //saves power
    		GPIO_Init(GPIOC, GPIO_Pin_All, GPIO_Mode_In_PU_No_IT);
    		GPIO_Init(GPIOD, GPIO_Pin_All, GPIO_Mode_In_PU_No_IT);
    		GPIO_Init(GPIOE, GPIO_Pin_All, GPIO_Mode_In_PU_No_IT);
    		GPIO_Init(GPIOF, GPIO_Pin_All, GPIO_Mode_In_PU_No_IT);
     
    		EXTI_config();
    		
    		halt(); //halt, not active halt because 
    		// //there is no LSE running
    		
    		GPIO_Init(GPIOE, GPIO_Pin_7, GPIO_Mode_Out_PP_Low_Slow); //pushpull
    		GPIO_SetBits(GPIOE, GPIO_Pin_7);
    		DELAY_ms(500);
    		GPIO_ResetBits(GPIOE, GPIO_Pin_7);
     
    	}

    small snippet from the interrupts, it just clears the ITPendingBit, nothing else is done.

    INTERRUPT_HANDLER(EXTI6_IRQHandler,14)
    {
    	if (EXTI_GetITStatus(EXTI_IT_Pin6) != RESET)
    	{
    		EXTI_ClearITPendingBit(EXTI_IT_Pin6);
    	}
    }

    and the initialization if the EXTI itself

    static void EXTI_config(void)
    {
    	GPIO_Init(GPIOE, GPIO_Pin_6, GPIO_Mode_In_FL_IT); //floating
    	
    	disableInterrupts(); //no iterrupts
    	EXTI_DeInit();
    	EXTI_ClearITPendingBit(EXTI_IT_Pin6);
    	EXTI_SetPinSensitivity(EXTI_Pin_6, EXTI_Trigger_Falling);
    	enableInterrupts();
    }

    If I remember well there was a button connected to PE6, that wakes up the mcu, a LED on PE7 went on for 500ms and then the mcu went back to halt mode. It was to check the current consumption in halt mode. (< 1 uA)

    DJosh.0Author
    Visitor II
    April 21, 2021

    Thank you for your answer, I will try it now .

    I want to ask another question ,

    I have configured two switches for external interrupt ,and i have to configure 3 rd switch to wake up the MCU ,

    Can you give me any suggestion what should i do, should I wakeup MCU from external interrupt or I should use RTC wakeup ,method ?

    thanks and regards

    Deoyani

    Visitor II
    April 21, 2021

    First, take care that you disable the external interrupts for those two switches if you do not want those to wakeup the mcu as well.

    And second it doesn't matter what you use to wakeup the mcu, EXTI is fine, RTC is fine, AWU is fine.

    But for RTC and AWU you cannot use HALT mode anymore, it will be ACTIVE HALT because there will be an oscillator running.

    DJosh.0Author
    Visitor II
    April 21, 2021

    I have implemented what you have sent me now, LED is blinking continuously , Am I doing something wrong ?

    And can you please explain me what the purpose of putting the Interrupt pin floating ?

    thanks for your continuous support

    thanks and regards

    Deoyani

    Visitor II
    April 21, 2021

    Blinking?

    If you just copied that code it should be OFF until you pull PE6 low, then it will be ON for 500ms and go OFF again when the mcu returns to halt.

    It could be that the "floating" is part of your problem here. I had a button with its own pullup resistor connected to PE6 and I wanted to measure only the mcu current in halt mode.

    Make it to GPIO_Init(GPIOE, GPIO_Pin_6, GPIO_Mode_In_PU_IT) and try again.

    DJosh.0Author
    Visitor II
    April 21, 2021

    I have implemented what you have sent me now, LED is blinking continuously , Am I doing something wrong ?

    And can you please explain me what the purpose of putting the Interrupt pin floating ?

    thanks for your continuous support

    thanks and regards

    Deoyani

    DJosh.0Author
    Visitor II
    April 21, 2021

    void EXTI_setup(void)

    {

       disableInterrupts();

       GPIO_Init(GPIOC, GPIO_Pin_0, GPIO_Mode_In_PU_IT);

       EXTI_DeInit();

       EXTI_ClearITPendingBit(EXTI_IT_Pin0);            //to be absolutely sure

       EXTI_SetPinSensitivity(EXTI_Pin_0, EXTI_Trigger_Rising_Falling);

       enableInterrupts();

    }

    /**

     * @brief external interrput handler .

            ResetRegistration Switch Interrupt handler   

     * @param None

     * @retval None

    */

     void ButtonIntHandler (void)

     {

          if (EXTI_GetITStatus(EXTI_IT_Pin0))

          {

           exti_signal = 1;

             ResetRegistration();

          }

          else if (EXTI_GetITStatus(EXTI_IT_Pin1))

          {

           //boollocklocked=IsLock();         

             

             //ui8PreviousState=ui8CurrentState;

             //ui8CurrentState=STATE_MOTOR_CONTROL;

          

          }

          EXTI_ClearITPendingBit(EXTI_IT_Pin0);

          EXTI_ClearITPendingBit(EXTI_IT_Pin1);

          

     }

    Is this above code correct for 2 exti interrupt ,

    With this code I am getting interrupt correctly for sometime , and for sometime , not getting interrupt .

    Am I missed out something in configuring or clearing Interrupt ?

    Please help me to resolve this problem.

    Thanks and Regards

    Deoyani

    DJosh.0Author
    Visitor II
    April 21, 2021

    And after changing it to GPIO_Mode_In_PU_IT I am getting the result as you said .

    Thank you

    Visitor II
    April 22, 2021

    :thumbs_up:

    DJosh.0Author
    Visitor II
    April 22, 2021

    void EXTI_setup(void)

    {

       disableInterrupts();

       GPIO_Init(GPIOC, GPIO_Pin_0, GPIO_Mode_In_PU_IT);

       EXTI_DeInit();

       EXTI_ClearITPendingBit(EXTI_IT_Pin0);            //to be absolutely sure

       EXTI_SetPinSensitivity(EXTI_Pin_0, EXTI_Trigger_Rising_Falling);

       enableInterrupts();

    }

    /**

     * @brief external interrput handler .

            ResetRegistration Switch Interrupt handler   

     * @param None

     * @retval None

    */

     void ButtonIntHandler (void)

     {

          if (EXTI_GetITStatus(EXTI_IT_Pin0))

          {

           exti_signal = 1;

             ResetRegistration();

          }

          else if (EXTI_GetITStatus(EXTI_IT_Pin1))

          {

           //boollocklocked=IsLock();         

             

             //ui8PreviousState=ui8CurrentState;

             //ui8CurrentState=STATE_MOTOR_CONTROL;

          

          }

          EXTI_ClearITPendingBit(EXTI_IT_Pin0);

          EXTI_ClearITPendingBit(EXTI_IT_Pin1);

          

     }

    Is this above code correct for 2 exti interrupt ,

    With this code I am getting interrupt correctly for sometime , and for sometime , not getting interrupt .

    Am I missed out something in configuring or clearing Interrupt ?

    Please help me to resolve this problem.

    Thanks and Regards

    Deoyani

    Visitor II
    April 22, 2021

    "Is this above code correct for 2 exti interrupt"

    No.

    You seem to want to use two GPIO with EXTI but you configure only one.

    DJosh.0Author
    Visitor II
    April 23, 2021

    Sorry I have not share you the configuration of 2nd GPIO , But I have configure in another file .

    but my handler is same.

    Is this the problem?

    thanks and regards

    Deoyani

    Visitor II
    April 25, 2021

    "Is this the problem?"

    Not if that code is called. Try single stepping and see where / when it does or doesn't work.