我使用这个MSP430F2370芯片目前在大规模使用中发现有些客户反馈程序无法正常使用,必须要断电重新启动才正常。程序在上电后会关看门狗2秒左右但是如果是检测到看门狗复位直接跳过,之后就初始化看门狗一直打开。现在感觉是干扰问题导致芯片无法启动看门狗复位,大家有没有遇到这种情况,有没有什么好的建议
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.
我使用这个MSP430F2370芯片目前在大规模使用中发现有些客户反馈程序无法正常使用,必须要断电重新启动才正常。程序在上电后会关看门狗2秒左右但是如果是检测到看门狗复位直接跳过,之后就初始化看门狗一直打开。现在感觉是干扰问题导致芯片无法启动看门狗复位,大家有没有遇到这种情况,有没有什么好的建议
程序在上电后会关看门狗2秒左右但是如果是检测到看门狗复位直接跳过
能否给出您的程序?另外请您在板子上测试一下下面的程序
/* --COPYRIGHT--,BSD_EX
* Copyright (c) 2012, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*******************************************************************************
*
* MSP430 CODE EXAMPLE DISCLAIMER
*
* MSP430 code examples are self-contained low-level programs that typically
* demonstrate a single peripheral function or device feature in a highly
* concise manner. For this the code may rely on the device's power-on default
* register values and settings such as the clock configuration and care must
* be taken when combining code from several examples to avoid potential side
* effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
* for an API functional library-approach to peripheral configuration.
*
* --/COPYRIGHT--*/
//******************************************************************************
// MSP430x24x Demo - Reset on Invalid Address fetch, Toggle P1.0
//
// Description: This program demonstrates how a reset is executed if the CPU
// tries to fetch instructions from within the module register memory address
// range (0x0000 --0x01FF) or from within unused address ranges. Toggle P1.0
// by xor'ing P1.0 inside of a software loop that ends with TAR loaded with
// 3FFFh - op-code for "jmp $". This simulates a code error. The MSP430F229
// will force a reset because it will not allow a fetch from within the address
// range of the peripheral memory, as is seen by return to the mainloop and
// LED flash.
// ACLK = n/a, MCLK = SMCLK = default DCO ~1.045Mhz
//
// MSP430F249
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// | P1.0|-->LED
//
// B. Nisarga
// Texas Instruments Inc.
// September 2007
// Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.42A
//******************************************************************************
#include <msp430.h>
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR |= 0x01; // Set P1.0 to output direction
TAR = 0x3FFF; // Valid opcode (for "jmp $")
for (;;)
{
volatile unsigned int i;
P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
i = 50000; // Delay
do (i--);
while (i != 0);
// C code to directly call an address location
((void (*)())0x170)(); // Invalid fetch ("call #0170h")
/* 0x170 is address of TAR register and is within the module register memory
address range (0x0000 --0x01FF) */
} // ** Should never get here **
}
我测试上面代码是不断重启MCU的,下面是我部分的代码
void main1(void)
{
//$$$ .初始化 - 关看门狗,设置时钟
//..........................................................................
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
OSCsel(SYS_CLK_8M); //set the oscilator
FCTL2 = FWKEY + FSSEL_2 + FN4 + FN3 + FN2 + FN1; // MCLK/2 for Flash Timing Generator
//$$$ .IO 初始化,设置TRF796x端口初始化
//.........................................................................
IO_INIT(); //IO初始化
PARset(); //TRF796x并行模式,端口设置
//$$$ .Modbu协议初始化
//.........................................................................
FLASH_INIT(); //FLASH,相关项目初始化
ModbusInit(DEV_infor.DevID, SendMultByte, UartBufMax); //modbus初始化
HostCommands(); //主机控制
}
void IO_INIT(void)
{
//$$$ .LED_ID, RS485 初始设置
//..........................................................................
P3DIR |= BIT6; // LED -- P3.6 - output
// P3REN |= BIT6; //LED--使能上拉电阻
//
P2DIR |= BIT3; // RS485EN --P2.3 - output
// P2REN |= BIT3; //RS485EN 使能上拉电阻
SetRS485_Rx; //使能RS485接收
//$$$ .LED_ID 开机闪烁控制
//..........................................................................
if((IFG1 & 0x01) == 0x00) //看门狗超时引起的重启不延时 2017年5月25日----
{
LED_ID_OFF; //LED灭
delay_ms(600); //上电LED先灭
LED_ID_ON; //LED亮
delay_ms(100); //定时不准 后面再调整
LED_ID_OFF; //LED灭
delay_ms(900); //上电LED先灭
LED_ID_ON; //LED亮
delay_ms(100); //定时不准 后面再调整
LED_ID_OFF; //LED灭
}
}
void OSCsel(unsigned char mode)
{
unsigned int ii1;
if (mode == 0x00) //select crystal oscilator
{
BCSCTL1 |= XTS + XT2OFF; // ACLK = LFXT1 HF XTAL
BCSCTL3 |= LFXT1S1; // 3 ?16MHz crystal or resonator
// turn external oscillator on
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (ii1 = 0xFF; ii1 > 0; ii1--); // Time delay for flag to set
}
while ((IFG1 & OFIFG) == OFIFG); // OSCFault flag still set?
BCSCTL2 |= SELM1 + SELM0 + SELS; // MCLK = SMCLK = HF LFXT1 (safe)
//return;
}
else //select DCO for main clock
{
if (CALBC1_8MHZ == 0xFF || CALDCO_8MHZ == 0xFF)
{
while (1); // If calibration constants erased
// do not load, trap CPU!!
}
//BCSCTL1:
BCSCTL1 = CALBC1_8MHZ; // Set DCO to 8MHz
DCOCTL = CALDCO_8MHZ;
BCSCTL1 &= ~XTS; //使能低频内部时钟12KHZ
//BCSCTL2: MCLK,SMCLK
BCSCTL2 = 0;
//BCSCTL3:
BCSCTL3 |= LFXT1S1; //LFXT1 范围选择 = VLOCLK
}
P1DIR |= 0x10; // P1.4 output direction
P1SEL |= 0x10; // P1.4 = SMCLK
}
void HostCommands()
{
POLLING = 0;
GucUIDLen = 0;
GucComRecCount = 0;
PcdAntennaOn(); //打开天线
ClrWDG(); //启动看门狗,超时0.6S重启
EnableInterrupts; //使能全局中断
while (1)
{
ClrWDG();
//主循环
}
}