Msp430 - (Still on the) Basics

| Comments

I was incorrect on the last post when I said our blinking fizzbuzz would need to step down to the LPM1 in order to use the watchdog timer, other than using external crystal. The watchdog timer, like I’ve said on the last post, can be sourced from a low-powered internal oscillator (VLO) which actually still active at LPM3.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// ...

// Setup Watchdog timer with ACLK
// sourced from VLO (LFXT1S_2) at ~12kHz
// so it will trigger interrupt within
// interval:
// (32/12) * 250ms) ~= ~670ms
BCSCTL1 |= DIVA_0;
BCSCTL3 |= LFXT1S_2;

// Disable watchdog for now
WDTCTL = WDTPW | WDTHOLD;

// ...

On the ISR we should alternate between deactivating the button interrupt with the watchdog timer like this:

From Port1’s ISR:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// ...

// Debounce~
// disable further interrupt from P1.3
P1IE  &= ~BIT3;
P1IFG  =  0;

// ...

// Enable Watchdog
WDTCTL = WDT_ADLY_250;
IFG1 &= ~WDTIFG;
IE1  |=  WDTIE;

// ...    

And here is from the watchdog timer’s ISR:

1
2
3
4
5
6
7
8
9
10
11
// ...

// Re-enable button push sensing
P1IE  |=  BIT3;
P1IFG  =  0;

// Stop watchdog
WDTCTL = WDTPW | WDTHOLD;
IE1   &= ~WDTIE;

// ...

I’ve setup git repository for tracking my progress, you can refer to complete source code here. The sources was to be compiled only with msp430gcc. Need to modify some ISR attribute if you want to compile them in CCS (with Texas Instrument’s own C compiler) or IAR.

Some note regarding msp430gcc, the complete setup for the development environment is explained really well here. Except that for some distro without static lib available on its repo cougharchlinuxcough we will need to recompile some library like expat to get the static variant, just download expat source code. Configure with:

1
2
3
$ ./configure --prefix=$SOMEFOLDER/expat --disable-shared --enable-static
$ make
$ make install

then export LDFLAGS to the lib folder before proceeding with msp430-gcc compilation just like described here:

1
2
3
4
$ export LDFLAGS='-L$SOMEFOLDER/expat/lib'

# would need to also do this if you don't have any expat library installed before
$ export CFLAGS='-i$SOMEFOLDER/expat/include'

That’s all.

Now I need to learn myself some PWM huft

Comments