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.

MSP430G2553: 使用定时器TIMER1_A1模拟串行口时,看门狗复位时间就改变了

Part Number: MSP430G2553

运行时看门狗的周期就不是1s,变成了32ms,发送到123后就复位

//------------------------------------------------------------------------------
// Hardware-related definitions
//------------------------------------------------------------------------------
#define UART_TXD 0x01 // TXD on P2.0 (Timer1_A.OUT0)
#define UART_RXD 0x02 // RXD on P2.1 (Timer1_A.CCI1A)

//------------------------------------------------------------------------------
// Conditions for 9600 Baud SW UART, SMCLK = 1MHz
//------------------------------------------------------------------------------
#define UART_TBIT_DIV_2 (8000000 / (9600 * 2))
#define UART_TBIT (8000000 / 9600)

void main(void){

WDT_init();
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
WDTCTL = WDT_ARST_1000; // Set Watchdog Timer timeout 1s

DCOCTL = 0x00;

BCSCTL1 = CALBC1_8MHZ;
DCOCTL = CALDCO_8MHZ; //MCLK SMCLK 8M ACLK 32.768

P2SEL = UART_TXD + UART_RXD; // Timer function for TXD/RXD pins
P2DIR &= ~UART_RXD;
P2DIR |= UART_TXD;
TimerA_UART_init(); // Start Timer_A UART

__enable_interrupt();

while(1){

WDTCTL = WDT_ARST_1000;
TimerA_UART_print("123456789abcdefghijklmn.\r\n");

}

//------------------------------------------------------------------------------
// Function configures Timer_A for full-duplex UART operation
//------------------------------------------------------------------------------
void TimerA_UART_init(void)
{ // 在输出模式 0 中,该位直接控制输出的状态
TA1CCTL0 = OUT; // Set TXD Idle as Mark = '1'
//同步捕捉源。 该位被用于使用定时器时钟同步捕捉输入信号
//CM1捕捉模式,上升沿捕捉
//cap捕捉模式 CCIE捕捉/比较中断使能。 该位启用相应 CCIFG 标志的中断请求
TA1CCTL1 = SCS + CM1 + CAP + CCIE; // Sync, Neg Edge, Capture, Int

TA1CTL = TASSEL_2 + MC_2; // SMCLK, start in continuous mode
}
//------------------------------------------------------------------------------
// Outputs one byte using the Timer_A UART
//------------------------------------------------------------------------------
void TimerA_UART_tx(unsigned char byte)
{
while (TA1CCTL0 & CCIE); // Ensure last char got TX'd
//计算一位时间
TA1CCR0 = TA1R; // Current state of TA counter
TA1CCR0 += UART_TBIT; // One bit time till first bit
//OUT 位值
TA1CCTL0 = OUTMOD0 + CCIE; // Set TXD on EQU0, Int
txData = byte; // Load global variable
txData |= 0x100; // Add mark stop bit to TXData
txData <<= 1; // Add space start bit
}

//------------------------------------------------------------------------------
// Prints a string over using the Timer_A UART
//------------------------------------------------------------------------------
void TimerA_UART_print(char *string)
{
while (*string) {
TimerA_UART_tx(*string++);
}
}
//------------------------------------------------------------------------------
// Timer_A UART - Transmit Interrupt Handler利用输出比较中断发送一个字节数据
//------------------------------------------------------------------------------
#pragma vector = TIMER1_A0_VECTOR
__interrupt void Timer_A0_ISR(void)
{
static unsigned char txBitCnt = 10;
//增加一位时间
TA1CCR0 += UART_TBIT; // Add Offset to CCRx
if (txBitCnt == 0) { // All bits TXed?
TA1CCTL0 &= ~CCIE; // All bits TXed, disable interrupt
txBitCnt = 10; // Re-load bit counter
}
else {
if (txData & 0x01) {
TA1CCTL0 &= ~OUTMOD2; // TX Mark '1'
}
else {
TA1CCTL0 |= OUTMOD2; // TX Space '0'
}
txData >>= 1;
txBitCnt--;
}
}
//------------------------------------------------------------------------------
// Timer_A UART - Receive Interrupt Handler
//------------------------------------------------------------------------------
#pragma vector = TIMER1_A1_VECTOR
__interrupt void Timer_A1_ISR(void)
{
static unsigned char rxBitCnt = 8;
static unsigned char rxData = 0;

switch (__even_in_range(TA1IV, TA1IV_TAIFG)) { // Use calculated branching
case TA1IV_TACCR1: // TACCR1 CCIFG - UART RX

TA1CCR1 += UART_TBIT; // Add Offset to CCRx

if (TA1CCTL1 & CAP) { // Capture mode = start bit edge
TA1CCTL1 &= ~CAP; // Switch capture to compare mode
TA1CCR1 += UART_TBIT_DIV_2; // Point CCRx to middle of D0
}
else {
rxData >>= 1;
//同步捕捉输入 所选择的 CCI 输入信号由EQUx 信号锁存,并可通过该位读取
if (TA1CCTL1 & SCCI) { // Get bit waiting in receive latch
rxData |= 0x80;
}
rxBitCnt--;
if (rxBitCnt == 0) { // All bits RXed?
rxBuffer = rxData; // Store in global variable
rxBitCnt = 8; // Re-load bit counter
TA1CCTL1 |= CAP; // Switch compare to capture mode
// __bic_SR_register_on_exit(LPM0_bits); // Clear LPM0 bits from 0(SR)
}
}
break;
}
}
//------------------------------------------------------------------------------

  • 您好

    针对你提到的MSP430G2553在使用定时器TIMER1_A1模拟串行口时看门狗复位时间改变的问题,这里有几个可能因素:

    1. 看门狗定时器与定时器冲突‌:

      • 当使用TIMER1_A1时,可能会与看门狗定时器的时钟或资源产生冲突。检查TIMER1_A1的配置,确保它没有意外地影响到看门狗定时器的时钟或操作。
      • 如果可能,尝试将看门狗定时器配置为使用不同的时钟源,以避免与TIMER1_A1的冲突。
    2. 软件喂狗不及时‌:

      • 在使用TIMER1_A1模拟串行口时,如果软件处理不及时,可能会导致无法按时喂狗,从而触发看门狗复位。
      • 优化你的代码,确保在定时器中断或串行口通信处理中能够及时喂狗。
    3. 看门狗定时器配置更改‌:

      • 检查你的代码,确保在配置TIMER1_A1时没有意外地更改了看门狗定时器的配置。
      • 重新检查并设置看门狗定时器的超时值和时钟源,以确保它们符合你的应用需求。
    4. 硬件问题‌:

      • 尽管不太常见,但硬件故障也可能导致看门狗复位时间改变。