This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430FR6922: Reset controller using watch dog timer if stuck in while loop.

Part Number: MSP430FR6922

Hello,

    I am working on msp430FR6922 controller. I have attached code for reference. during testing sometimes my code is getting stuck in " while(!((P4IN&BIT6)==0)){}  " statement. 

I want to reset msp430 controller using WDT after 1 second when code is stuck in while statement. So, controller restart the code...

int main(void)
{
   WDTCTL = WDT_ARST_1000 ;                 // Stop WDT

   dev_init_16M();                           // Microcontroller set on 16MHz
 
   __enable_interrupt();                     // Re-enable all interrupts
   __bis_SR_register(GIE);                   // Enter LPM3, interrupts enabled

  DelayStart=1;

  while (1)
  {
     if(DelayStart==1)                       // For sample 1 send LC data after every 1 sec to tare the LC readings
      {
         // (DCO=MCLK=16MHZ )so,
         // Count/MCLK freq=Time
         // 16000000/16MHz=1sec
         __delay_cycles(16000000);                        // delay calculate on 16 MHz

         //timer interrupt on
         while(!((P4IN&BIT6)==1)){}                       // Wait until data ready
         CurrentLCValue=ReadData();                       // Read load cell data
         CurrentLCValue1=CurrentLCValue&0x7FFF;

         LongtoInt.LongData=CurrentLCValue;               // Split 3 byte data into single byte
         giTransmitBuffer[0]=LongtoInt.ByteSplit[1];
         giTransmitBuffer[1]=LongtoInt.ByteSplit[0];
         giTransmitBuffer[2]=0x00;

         for(i=0;i<3;i++)      // Upto array from start to CRC lenth
         {
             while(!(UCA0IFG&UCTXIFG));
             UCA0TXBUF =  giTransmitBuffer[i];
         }
   }

}
my question is WDT is helpful when controller is getting stuck in while statement?? is there any other way to reset the controller through software?? if yes write code for msp430fr6922 controller.

  • What happens when you run this code? My guess is that it resets during the __delay_cycles(). To see whether this happens, set a breakpoint on the second line of main() [the debugger sometimes uses the first line]. Your code can check with something like "if (SYSRSTIV == SYSRSTIV_WDTTO)", but you won't be able to tell where it happened.

    More generally, you need to feed the watchdog periodically in your loop (at least once per second in this case). You can use the same code you used to start it, i.e.:

    >  WDTCTL = WDT_ARST_1000 ; // Feed watchdog -- 1 sec using ACLK

    -----------------

    Unsolicited:

    >  while(!((P4IN&BIT6)==1)){} // Wait until data ready
    This will always loop forever since (P4IN&BIT6) can only be ==0 or ==BIT6. I suspect you wanted

    > while((P4IN&BIT6)==0){} // Wait until data ready (P4.6 goes high)
     

    [Edit: Fixed comment]

**Attention** This is a public forum