Jump to content
Sign in to follow this  
everettpattison

WDTCTL and Macros

Recommended Posts

Hello,


I am new to the MSP430 Launchpad and am trying to get familiar with CCS5 and the MS430. I am trying to use macros to control the watch dog timer but I can't seem to get it working. The code builds fine but when it gets run it gets hung up and won't give me any kind of error until I pause. The error is as follows:

 

Can't find a source file at "/tmp/TI_MKLIBTw7SkT/SRC/autoinit.c"

 

Though, I am able to get it working if I set all the bits at once. See below for examples.

 

This does not work....

 

#define wdt_password_set()             ( WDTCTL |= WDTPW )

#define wdt_mode_interval()             ( WDTCTL |= WDTTMSEL)

#define wdt_clear()                            ( WDTCTL |= WDTCNTCL )

#define wdt_source_aclk()                ( WDTCTL |= WDTSSEL )

#define wdt_divider_8192()              ( WDTCTL |= WDTIS1 )

 

wdt_password_set();

wdt_mode_interval();

wdt_clear();

wdt_source_aclk();

wdt_divider_8192();

 

 

But, this line of code works perfectly...

 

WDTCTL = WDTPW | WDTTMSEL | WDTCNTCL | WDTSSEL | WDTIS1;

 

Is there something that I am missing completely?

 

Thanks in advance.

 

Everett

Share this post


Link to post
Share on other sites

WDTCTL = WDTPW | WDTTMSEL | WDTCNTCL | WDTSSEL | WDTIS1;

 

Is there something that I am missing completely?

Yes; WDTCTL is an unusual register in that what you read back is not what you write. In particular, the value of the high byte when read will be 0x69, but it must be written as 0x5a. A read-modify-write operation will generate an invalid write causing the MCU to reset.

Share this post


Link to post
Share on other sites

Yes; WDTCTL is an unusual register in that what you read back is not what you write. In particular, the value of the high byte when read will be 0x69, but it must be written as 0x5a. A read-modify-write operation will generate an invalid write causing the MCU to reset.

 

Thanks for the information! Are there any other registers that are similar to this?

Share this post


Link to post
Share on other sites

Thanks for the information! Are there any other registers that are similar to this?

Offhand I can think of PMMCTL (power management) and PMAPKEYID (port mapping) on 5xx MCUs, and CSCTL0 on FRAM devices.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...