C code for Stop-3 using RTC wake  in MC9S08SH8 microcontroller

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

C code for Stop-3 using RTC wake  in MC9S08SH8 microcontroller

1,490 Views
ellendula
Contributor I

Hi...

I want to implement stop mode in my application. please provide the simple "c" code for implementing the stop-3 mode and waking stop-3 using RTC with 1KHz clock source .

it is very urgent, i have to include in my application.

Labels (1)
0 Kudos
3 Replies

452 Views
bigmac
Specialist III

Hello Shiva,

 

You will need to use inline assembly to implement the STOP instruction using C, i.e __asm stop;

Possibly you might create a macro to do this.

#define enter_stop  __asm stop

 

Prior to entering stop mode, you would also need to enable the RTC interrupt.  The ISR for the RTC module should clear the flag, and maybe disable further RTC interrupts.

 

During MCU initialisation, you will also need to configure for stop3 mode, and enable the STOP instruction, per the datasheet..

 

When stop3 mode is exited, the ISR code will be executed, and the operation will then continue immediately following the STOP instruction.

 

Regards,

Mac

 

0 Kudos

452 Views
ellendula
Contributor I

Hi...

 

thank yu for the reply....

 

i'm using RTC for waking the stop-3 mode. and i'm using MC9S08SH8 8-bit microcontroller in my application.

and the initialisations are:

 

#define   x   0x01

#define   y   0xFE

main()

{

 

        for( ; ; )

        {

                  RTCSC = 0x1F;  //1sec  1khz clock source is enabled.with RTIE enabled

                  if( Z & x)                //refer above for x

                  {

                               Z = Z  & y;    //refer above for y

                                _Stop;

                   }

                    __RESET_WATCHDOG(); /* feeds the dog */

         }

}


void interrupt VectorNumber_Vtpm1ovf timerPWM(void)              //timer interrpt for 0.1sec
{
     TPM1SC_TOF=0;

     PTAD_PTAD2 = ~ PTAD_PTAD2; //for checking purpose

     Z = 0x01;  

}

 

void interrupt VectorNumber_Vrtc  realtimeinterrupt(void)
{  
      RTCSC_RTIF = 1; //for clearing RTIF flag.

      RTCSC_RTIE = 0;

}

 

In the above case, RTC not waking properly, and the two ISR's are not working exactly. so, please ttell me where the problem is occuring.i.e, when the stop instruction in the for loop is seen, it enter into stop and after one sec, RTC interrupt comes, because i uased 1KHz clock source. and the RTC interrupt flag clear , and after that bus_clock everything has to work normally but it is not going to timer PWM ISR immediately it is taking large time to go to timer interrupt. so, im thinking some wrong i'm making in the initialisation.

In case of enabling the RTC , initialisation is sufficient or anything has to be done. and 1KHz source can be used for RTC to wake from STOP-3 mode. and please provide the solution for the above problem as early as possible.

 

 

0 Kudos

452 Views
bigmac
Specialist III

Hello Shiva,

 

I am not sure I completely understand your problem.  However keep in mind the following factors:

 

  1. If you require that the RTC be the sole wakeup source, you will need to disable all other possible interrupt sources, including the TPM interrupts, prior to entering stop mode.  The code within the RTC ISR would need to re-enable any TPM interrupts that may be required.
  2. Simply disabling the RTC interrupt within the RTC ISR will mean that the RTC module will continue to count after wakeup.  Then if you re-enable the RTC interrupt only, prior to entering the next stop mode, you  are unlikely to achieve the correct stop duration.

 

Regards,

Mac

 

 

0 Kudos