0
\$\begingroup\$

I am using MC9S08DZ96 microcontroller and I using CodeWarrior version 11. I want to put the MCU to sleep mode(STOP3). In the CPU settings, I have changed the sleep mode setting and the relevant registers have been activated.

enter image description here

I know with the asm stop; command MCU goes to sleep mode. But it doesn't work. I think #define StopMode {asm STOP;} command, should be defined somewhere. Does anyone know how to define stop mode? These are my registers:

void _EntryPoint(void)
{
  /* ### MC9S08DZ128_64 "Cpu" init code ... */
  /*  PE initialization code after reset */
  /* Common initialization of the write once registers */
  /* SOPT1: COPT=0,STOPE=1,SCI2PS=0,IIC1PS=0,??=0,??=0,??=0 */
  setReg8(SOPT1, 0x20U);  
              
  /* SOPT2: COPCLKS=0,COPW=0,??=0,ADHTS=0,??=0,MCSEL=0 */
  setReg8(SOPT2, 0x00U); 
               
  /* SPMSC1: LVWF=0,LVWACK=0,LVWIE=0,LVDRE=1,LVDSE=1,LVDE=1,??=0,BGBE=0 */
  setReg8(SPMSC1, 0x1CU); 
              
  /* SPMSC2: ??=0,??=0,LVDV=0,LVWV=0,PPDF=0,PPDACK=0,??=0,PPDC=0 */
  setReg8(SPMSC2, 0x00U);
               
  /*  System clock initialization */
  /*lint -save  -e923 Disable MISRA rule (11.3) checking. */

  if (*(uint8_t*)0xFFAFU != 0xFFU) {   
/* Test if the device trim value is stored on the specified address */
    MCGTRM = *(uint8_t*)0xFFAFU;       
/* Initialize MCGTRM register from a non volatile memory */
    MCGSC = *(uint8_t*)0xFFAEU;        
/* Initialize MCGSC register from a non volatile memory */
  }

  /*lint -restore Enable MISRA rule (11.3) checking. */
  /* MCGC2: BDIV=0,RANGE=0,HGO=0,LP=0,EREFS=0,ERCLKEN=0,EREFSTEN=1 */
  setReg8(MCGC2, 0x01U);               /* Set MCGC2 register */ 

  /* MCGC1: CLKS=0,RDIV=0,IREFS=1,IRCLKEN=1,IREFSTEN=1 */
  setReg8(MCGC1, 0x07U);               /* Set MCGC1 register */ 

  /* MCGC3: LOLIE=0,PLLS=0,CME=0,DIV32=0,VDIV=1 */
  setReg8(MCGC3, 0x01U);               /* Set MCGC3 register */ 

  /* MCGT: ??=0,??=0,DMX32=0,??=0,??=0,??=0,??=0,DRST_DRS=0 */
  setReg8(MCGT, 0x00U);                /* Set MCGT register */ 
  

  /*** End of PE initialization code after reset ***/
  /*lint -save  -e950 Disable MISRA rule (1.1) checking. */

  __asm   jmp _Startup ;               /* Jump to C startup code */
  /*lint -restore Enable MISRA rule (1.1) checking. */
}
\$\endgroup\$
7
  • \$\begingroup\$ Is this your reset vector? If it is, where is the SP set? If not, then who calls _EntryPoint? \$\endgroup\$
    – Lundin
    Commented Feb 6, 2023 at 10:58
  • \$\begingroup\$ @Lundin This is the function of the MCU clock registers, when I activate the stop instruction enable settings that I put in the picture. Some registers like STOPE are changed. In part main() , I don't call this function again. \$\endgroup\$ Commented Feb 6, 2023 at 11:10
  • \$\begingroup\$ I don't understand how to read this still, since _Startup is the CRT, meaning that _EntryPoint is either your reset vector, in which case it is incorrectly written, or it gets called from the reset vector, in which case it would be interesting to see the reset vector too. \$\endgroup\$
    – Lundin
    Commented Feb 6, 2023 at 11:15
  • \$\begingroup\$ Any reset vector for HCS08 must have a TSX asm instruction to set the SP and before you do this, you can't really execute C code. \$\endgroup\$
    – Lundin
    Commented Feb 6, 2023 at 11:18
  • \$\begingroup\$ You are right. I have a function for clock called MCG_init() . The _EntryPoint function is generated in the cpu.c file and this description is written above it. Initializes the whole system like timing and so on. At the end of this function, the C startup is invoked to initialize stack, memory areas and so on. This method is internal. It is used by Processor Expert only. \$\endgroup\$ Commented Feb 6, 2023 at 11:45

1 Answer 1

1
\$\begingroup\$

This problem was solved. Instead of calling function _EntryPoint again, I wrote a function in file main.c and called this function before the command asm(stop);:

void stop3() {
    setReg8(SOPT1, 0x20U);                
    setReg8(SOPT2, 0x00U);                
    setReg8(SPMSC1, 0x1CU);               
    setReg8(SPMSC2, 0x00U);
}

Then, In main() I called the above function:

while(1) {
    if (T_Timer >= 10000) {
        stop3();
        asm(stop);
    }
}

With this, the normal consumption, which was 60 mA, was reduced to 40 mA, which, if we don't consider that the LEDs of the circuit are on, will significantly reduce the consumption.

\$\endgroup\$
1
  • \$\begingroup\$ You should accept your own answer. The rules allow that. Accepting your own answer (or any answer) adds credibility to the answer and that's something that others users will find useful in the future. It's a kind of evidence that "this worked". \$\endgroup\$
    – Andy aka
    Commented Apr 10, 2023 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.