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.

用CCS設計MSP430F5338的WDTCNTCL無法動作為1

Other Parts Discussed in Thread: MSP430F5338

你好:

我在CCS環境下用使用MSP430F5338開發自己的設計的板子

程式如下,其中WDTCNTCL預設定Watchdog timer counter clear,bit3應該為1, 但在debug的Registers顯示bit3始終為0 (下圖右下角顯示)

WDTCTL =WDTPW+WDTCNTCL;
_EINT();

請問是什麼原因讓WDTCNTCL無法動作?

  • 您可以点击右下角寄存器WDTCTL前面的箭头来展开,从而查看WDTCNTCL的值。我这边没有这个板子,所以不好debug来查看

    请问现在您是想如何使用WDT呢?在下面的链接TI给出了相关的例程

    dev.ti.com/.../node

    WDTCNTCL:Watchdog timer counter clear. Setting WDTCNTCL = 1 clears the count value to 0000h. WDTCNTCL is automatically reset.

    0b = No action
    1b = WDTCNT = 0000h
  • 你好,我點選右下角寄存器WDTCTL前面的箭头来展开後,查看WDTCNTCL的值為0
    但我程式WDTCTL =WDTPW+WDTCNTCL這樣寫, WDTCNTCL應該是1,
    所以我不解為何這個值是0
  • 请您参考下用户指南

    www.ti.com.cn/.../slau208q.pdf

    16.2 WDT_A Operation

    WDTCTL is a 16-bit password-protected read/write register. Any read or write access must use word instructions and write accesses must include the write password 05Ah in the upper byte. Any write to WDTCTL with any value other than 05Ah in the upper byte is a password violation and triggers a PUC system reset, regardless of timer mode. Any read of WDTCTL reads 069h in the upper byte. Byte reads on WDTCTL high or low part result in the value of the low byte. Writing byte wide to upper or lower parts of WDTCTL results in a PUC.

    执行下面的命令时:
    WDTCTL =WDTPW+WDTCNTCL;
    您执行读取/修改/写入操作。这意味着将读取WDCTL的内容,将其修改为要更改的位,然后再写回。

    当您读取WDTCTL时,您在高字节中得到一个0x69h。现在,您可以通过用0x5Ah(= WDTPW)进行“或”操作来修改高字节,这将导致0x7Bh。这是错误的密码,MSP430将生成一个PUC。因此,此命令将不起作用。
  • 你好:
    我已執行WDTCTL =WDTPW+WDTCNTCL;其中WDTPW這個指令是高字節的0x5Ah已經可以進行操做修改後面欲控制的WDTCNTCL,而者個指令在執行時應該為1,但實際在執行時卻始終是0,請問為何無法變更?
  • 以下3個問題再麻煩你:
    1. 我已執行WDTCTL =WDTPW+WDTCNTCL;
    其中WDTPW這個指令是高字節的0x5Ah已經可以進行操做修改後面欲控制的WDTCNTCL,
    WDTCNTCL在單部執行應該會改變為1,但我不論是否有寫WDTCNTCL這個指令,
    CCS單步執行的圖右下角WDTCNTCL始終為0,
    請問我要如何確定WDTCNTCL有動作了? 為何無法修改WDTCNTCL?

    2. 是否在沒有執行WDTCNTCL(餵狗)才會跳到中斷#pragma vector=WDT_VECTOR
    __interrupt void watchdog_timer(void)
    若已執行WDTCNTCL(餵狗)將不會跳到watchdog的中斷?

    3. 麻煩你提供一個watchdog範例,在沒有執行WDTCNTCL(餵狗)時會跳到__interrupt void watchdog_timer(void)
    當程式執行到WDTCNTCL(餵狗)將清除watchdog,程式不會跳到__interrupt void watchdog_timer(void)執行

  • 如之前所说

    WDTCTL |= WDTPW + WDTCNTCL;

    WDTPW位读出来是0x69,而需要写入的是0x5A,实际上0x69|0x5A=0x7B,这就造成了在喂狗的时候,密码错误造成单片机重启

    而WDTCNTCL reset的默认值是0,并且 WDTCNTCL is automatically reset.

    清零完成之后WDTCNTCL会自动复位为0,所以CCS看到的是0

  • 而且 WDTIFG

    Watchdog timer interrupt flag. In watchdog mode, WDTIFG will self clear upon a watchdog timeout event. The SYSRSTIV can be read to determine if the reset was caused by a watchdog timeout event.

    我查看debug例程后SYSRSTIV 为0x16

    #include <msp430.h>

    int main(void)
    {
    P1DIR |= 0x01; // Set P1.0 to output - SET BREAKPOINT HERE
    P1OUT ^= 0x01; // Toggle P1.0

    __bis_SR_register(LPM4_bits + GIE); // Enter LPM4, Stop all clocks
    __no_operation(); // For debugger
    }
  • 謝謝妳的協助,問題已經解決了!

  • 很高兴能帮到您!