MC9S12G128 wake up from Pseudo Stop Mode

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

MC9S12G128 wake up from Pseudo Stop Mode

Jump to solution
1,125 Views
1090097669
Contributor III

MC9S12G128 wake up from Pseudo Stop Mode,After Wake up Where is the program running position? if MCU wakes up from Isr,How to make the chip rerun to the main function without resetting?

I am using this chip for Pseudo Stop Mode,and wake it up from can wake up Interrupt ,however ,i can not confirm the program runing position after MCU waked,and MCU encounter reset ,Please check my fault of my code;

void interrupt Vcanwkup_ISR(void)
{
CANRFLG_WUPIF = 1;
CANRFLG = 0x80;
CANCTL0 = 0x00;
CANRIER = 0x01;
PLL_init();
if(TRUE == systemGotoSleepModeFlag)
{
//_MCU_Reset();
_MCU_Reset_Flag = 1;
}
}

the other function

{

    if(_MCU_Reset_Flag == 1)
{
_MCU_Reset_Flag = 0;
_MCU_Restart(); 
}
 

}

 

thanks very much

Regards!

Labels (1)
1 Solution
890 Views
RadekS
NXP Employee
NXP Employee

Hi Katrinal,
when MCU wake-up from stop mode, the CPU executes ISR and after that, it returns on next instruction just below STOP instruction.
Note: the STOP instruction must not be executed from ISR (where I-bit is set and MCU cannot wake-up by I-bit maskable interrupts).

See attached example code for CAN wake-up from stop mode (for S12XE).

commands for enable CAN wake-up (inside CAN init function):

CANCTL0_WUPE = 1; //wake up enable
 CANRIER_WUPIE = 1; //wake up interrupt enable


commands for go to sleep (somewhere in main() function):

CANCTL0_SLPRQ = 1; //sleep mode request
 while(CANCTL1_SLPAK == 0); //wait for acknowledge of sleep mode
 
 asm ANDCC #0x7F; //clear S bit
 asm nop;
 asm STOP; //STOP mode‍‍‍‍‍‍‍‍‍

example of CAN wake-up test ISR:

#pragma CODE_SEG NON_BANKED
interrupt VectorNumber_Vcanwkup void CAN_WAKE(void)
{
 while(1){
//add code for LED toggling here - according your board
 for(i=0; i<50000; i++){
 asm nop;
 }
 }
}
#pragma CODE_SEG DEFAULT‍‍‍‍‍‍‍‍‍‍‍‍‍

We have to enter CAN sleep mode (it waits until all Tx buffers are empty and current Rx transfer finish) before MCU STOP instruction execution for avoiding generating invalid messages on CAN bus.

I hope it helps you.

Radek

View solution in original post

3 Replies
891 Views
RadekS
NXP Employee
NXP Employee

Hi Katrinal,
when MCU wake-up from stop mode, the CPU executes ISR and after that, it returns on next instruction just below STOP instruction.
Note: the STOP instruction must not be executed from ISR (where I-bit is set and MCU cannot wake-up by I-bit maskable interrupts).

See attached example code for CAN wake-up from stop mode (for S12XE).

commands for enable CAN wake-up (inside CAN init function):

CANCTL0_WUPE = 1; //wake up enable
 CANRIER_WUPIE = 1; //wake up interrupt enable


commands for go to sleep (somewhere in main() function):

CANCTL0_SLPRQ = 1; //sleep mode request
 while(CANCTL1_SLPAK == 0); //wait for acknowledge of sleep mode
 
 asm ANDCC #0x7F; //clear S bit
 asm nop;
 asm STOP; //STOP mode‍‍‍‍‍‍‍‍‍

example of CAN wake-up test ISR:

#pragma CODE_SEG NON_BANKED
interrupt VectorNumber_Vcanwkup void CAN_WAKE(void)
{
 while(1){
//add code for LED toggling here - according your board
 for(i=0; i<50000; i++){
 asm nop;
 }
 }
}
#pragma CODE_SEG DEFAULT‍‍‍‍‍‍‍‍‍‍‍‍‍

We have to enter CAN sleep mode (it waits until all Tx buffers are empty and current Rx transfer finish) before MCU STOP instruction execution for avoiding generating invalid messages on CAN bus.

I hope it helps you.

Radek

890 Views
1090097669
Contributor III

Hi Radek,

   there is a question that  after the chip sleeps, power on again after a period of time (About 20s), it may automatically trigger a CAN wakeup interrupt, resulting in an incorrect process,How to avoid this phenomenon?

0 Kudos
890 Views
1090097669
Contributor III

Hi Radek,

      Unfortunately,it did not work , The function I want to complete is prohibiting MCU resetting Since I set up the bootloader,however, MCU enter Reset Status  after waking  up by Can Interrupt ,because I am able to read BootLoader status firstly ,then MCU enter Appliction program,Blow is my code ,please point my fault ,Thanks!

void SleepPro(void)

{

    if(1 == WAKE_OBC_DAT)
   {
      systemGotoSleepModeFlag = 1 ;
      MCU_Stop();/*open Can Wake up and go to sleep*/
      if(_MCU_Reset_Flag == 1)
      {
      _MCU_Reset_Flag = 0;
      _Startup();
      }
   }
   else
   {
      systemGotoSleepModeFlag = 0;
   }

}   

void interrupt Vcanwkup_ISR(void)
{
   CANRFLG_WUPIF = 1;
   CANRFLG = 0x80;
   CANCTL0 = 0x00;
   CANRIER = 0x01;
   PLL_init();
   if(TRUE == systemGotoSleepModeFlag)
   {
   _MCU_Reset_Flag = 1;
   }
}

0 Kudos