Quantcast
Channel: MSP low-power microcontroller forum - Recent Threads
Viewing all articles
Browse latest Browse all 21954

MSP432P401R Launchpad, waking up from LPM3

$
0
0

Hello,

I think I am able to enter LPM3 successfully but I noticed whenever I wake up the MCU with the pushbutton using edge interrupt, the MCU wakes up but the clock does not return to the original state before it entered LPM3. Before entering LPM3, I my MCLK was HFXT 48MHz / 4 = 12MHz. I tried various waits. I had a while loop to wait if the clock is ready and to wait if the CM mode is at AM LDO VCORE0 and still, my clock would never return to 12 MHz even after the while loops.. I know because my LED blink timing was way off. To solve the problem, this is what I did,

void PORT1_IRQHandler(void)
{
 volatile uint32_t pressCount, notPressCount;
 
 if(DeepSleepFlag == 1)
 {
  Configure_MCLK_12MHz();
  Enable_LFXT_32768KHz();
  SCB->SCR &= 0xFFFFFFE9;
  DeepSleepFlag = 0;  
 }//end if(DeepSleepFlag == 1)

......

}

Notice in the beginning of my interrupt handler, I initialize my clocks again. After doing this, everything was back to normal. But I was under the impression that waking up from LPM3 would return you back to the state you were before entering. Any thoughts? Previously I had a while loop checking if the clocks were ready instead of Configure MCLK and Enable LFXT, but that didn't work.

Here is my code before entering LPM3

   WDTCTL = WDTPW | WDTHOLD;
   Configure_Deep_Sleep_Parameters();
   SCB->SCR |= 0x00000004;
   __wfi();

void Configure_Unused_Ports(void)
{
 P1DIR |= 0xED;
 P2DIR = 0xFF;
 PBDIR = 0xFFFF;
 PCDIR = 0xFFFF;
 PDDIR = 0xFFFF;
 PEDIR = 0xFFFF;
 P1OUT &= 0x12;
 P2OUT = 0x00;
 PBOUT = 0x0000;
 PCOUT = 0x0000;
 PDOUT = 0x0000;
 PEOUT = 0x0000; 
}//end void Configure_Unused_Ports(void)
/***********************************************/
void Configure_Deep_Sleep_Parameters(void)
{
 Configure_Unused_Ports();
 
 while((PCM->CTL1 & 0x00000100) == 0x00000100)
 {
  //wait until PMR_BUSY = 0 to signal PCMTL0 and CS ready
 }//end while(PCM->CTL1 & 0x00000100)
 
 PCM->CTL1 = (PCM->CTL1 & 0x0000FFF8) | 0x695A0000 | 0x00000004; //enable LPM3 force entry
 PCM->CTL0 = (PCM->CTL0 & 0x0000FF0F) | 0x695A0000 | 0x00000000; //request for LPM3
 
 while((PCM->CTL1 & 0x00000100) == 0x00000100)
 {
  //wait until PMR_BUSY = 0 to signal PCMTL0 and CS ready
 }//end while(PCM->CTL1 & 0x00000100)
}//end void Configure_Deep_Sleep_Parameters(void)
/***********************************************/

Below is my code when I initialized my clocks:

void Configure_MCLK_12MHz(void)

 //This section is necessary to ensure VCORE level supports 48MHz crystal
 //by requesting AM LDO VCORE1
 while((PCM->CTL1 & 0x00000100) == 0x00000100)
 {
  //wait until PMR_BUSY = 0 to signal PCMTL0 and CS ready
 }//end while(PCM->CTL1 & 0x00000100)
 
 PCM->CTL0 = (PCM->CTL0 & 0x0000FFF0) | 0x695A0000 | 0x00000001; //request AM LDO VCORE1
 while((PCM->CTL0 & 0x00003F00) != 0x00000100)
 {
  //wait until CPM = 1, current pwer mode = AM LDO VCORE1
 }//end while((PCM->CTL0 & 0x00003F00) != 0x00000100)
 
 while((PCM->CTL1 & 0x00000100) == 0x00000100)
 {
  //wait until PMR_BUSY = 0 to signal PCMTL0 and CS ready
 }//end while(PCM->CTL1 & 0x00000100)
 /***********************************************/
 //This section enables HFXT and sets MCLK = 12MHz, HSMCLK = 6MHz, SMCLK = 3MHz
 //ACLK and BCLK sourced by REFO_CLK at 32.768KHz
 PJSEL0 |= 0x0C; //PJ.3 is HF out, PJ.2 is HF in
 PJSEL1 &= 0xF3; 
 
 CS->KEY = 0x0000695A; //unlock clock system registers
 
 while((CS->STAT & 0x1F000000) != 0x1F000000)
 {
  //wait until clocks are ready
 }//end while((CS->STAT & 0x1F000000) != 0x1F000000)
 

 CS->CTL2 = (CS->CTL2 & 0xFDE9FC03) | 0x01610000;
 
 while((CS->IFG & 0x00000002) == 0x00000002) //HFXT fault
 {
  CS->CLRIFG = 0x00000002; //continue clearing the fault flags until clock have stabilized.
 }//end while(CS->IFG & 0x00000002)
 CS->CLRIFG = 0x00000200; //clear HFXT start fault counter
  
 
 CS->CTL1 = (CS->CTL1 & 0xC8BAFADD) | 0x40321255;
 
 while((CS->STAT & 0x1F000000) != 0x1F000000)
 {
  //wait until clocks are ready
 }//end while((CS->STAT & 0x1F000000) != 0x1F000000)
 
 CS->KEY = 0; //lock clock system registers
 /***********************************************/
 //This section switches power mode back to AM LDO VCORE0
 //AM LDO VCORE0 supports 12MHz
 while((PCM->CTL1 & 0x00000100) == 0x00000100)
 {
  //wait until PMR_BUSY = 0 to signal PCMTL0 and CS ready
 }//end while(PCM->CTL1 & 0x00000100)
 
 PCM->CTL0 = (PCM->CTL0 & 0x0000FFF0) | 0x695A0000 | 0x00000000; //request AM LDO VCORE0
 
 while((PCM->CTL0 & 0x00003F00) != 0x00000000)
 {
  //wait until CPM = 0, current pwer mode = AM LDO VCORE0
 }//end while((PCM->CTL0 & 0x00003F00) != 0x00000000)
 
 while((PCM->CTL1 & 0x00000100) == 0x00000100)
 {
  //wait until PMR_BUSY = 0 to signal PCMTL0 and CS ready
 }//end while(PCM->CTL1 & 0x00000100)
}//end void Set_MOSC_12MHz(void)
/***********************************************/
void Enable_LFXT_32768KHz(void)
{
 while((PCM->CTL1 & 0x00000100) == 0x00000100)
 {
  //wait until PMR_BUSY = 0 to signal PCMTL0 and CS ready
 }//end while(PCM->CTL1 & 0x00000100)
 
 PJSEL0 |= 0x03; //PJ.1 is LF out, PJ.0 is LF in
 PJSEL1 &= 0xFC; 
 
 CS->KEY = 0x0000695A; //unlock clock system registers
 
 while((CS->STAT & 0x1F000000) != 0x1F000000)
 {
  //wait until clocks are ready
 }//end while((CS->STAT & 0x1F000000) != 0x1F000000)
 
 CS->CTL2 = (CS->CTL2 & 0xFDE9FD00) | 0x00000100;
 
 while((CS->IFG & 0x00000001) == 0x00000001) //LFXT fault
 {
  CS->CLRIFG = 0x00000001; //continue clearing the fault flags until clocks have stabilized.
 }
 CS->CLRIFG = 0x00000100; //continue clearing the fault flags until clocks have stabilized.
 
 CS->CTL1 &= 0xC8BAE8DD; //BCLK, ACLK source is LFXT
 
 while((CS->STAT & 0x1F000000) != 0x1F000000)
 {
  //wait until clocks are ready
 }//end while((CS->STAT & 0x1F000000) != 0x1F000000)
 
 CS->KEY = 0; //lock clock system registers
 
 while((PCM->CTL1 & 0x00000100) == 0x00000100)
 {
  //wait until PMR_BUSY = 0 to signal PCMTL0 and CS ready
 }//end while(PCM->CTL1 & 0x00000100)
}//end void Enable_LFXT_32768KHz(void)
/***********************************************/

Thanks

AJ


Viewing all articles
Browse latest Browse all 21954

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>