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控制器。 我附上了供参考的代码。 在测试过程中、有时我的代码卡在" while (!((P4IN&BIT6)==0)}" 语句中。
当代码停留在 while 语句中时、我想在1秒后使用 WDT 复位 MSP430控制器。 因此、控制器重新启动代码...
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]; } } }
当您运行此代码时会发生什么情况? 我猜它会在__delay_cycles ()期间复位。 要查看是否发生这种情况,请在 main()的第二行设置断点[调试器有时使用第一行]。 您的代码可以使用类似"if (SYSRSTIV == SYSRSTIV_WDTTO)"的内容进行检查、但您无法判断发生了什么情况。
更一般而言、您需要在环路中定期为看门狗馈送电流(在本例中至少每秒一次)。 您可以使用与启动代码相同的代码、即:
>WDTCTL = WDT_ARST_1000;// 使用 ACLK 馈送看门狗-1秒
--------
未经请求:
> while (!((P4IN&BIT6)=1){}//等待数据就绪
这将一直循环、因为(P4IN&BIT6)只能= 0或= BIT6。 我怀疑您有需要
> while (((P4IN&BIT6)=0){}//等待数据就绪(P4.6变为高电平)
[编辑:固定注释]