411
Explanation
To keep things simple, I demoed another LED blinking code. Notice that with inclusion of driverlib,
everything has changed with meaningful functions. Take the setting of watchdog timer as an example.
WDTCTL = WDTPW | WDTHOLD; //Register-level access
WDT_A_hold(WDT_A_BASE); //DriverLib function call
Instead of setting registers, driverlib functions are just taking some function argument(s) to set desired
pin according to our wish. The functions and the arguments have meaningful names instead of magical
numbers. This way of coding gives a fast overview of our code and the development time and efforts
are greatly reduced. All register-level tasks are done under the hood of driverlib. This doesn’t however
restrict us from going the old-fashioned way of using register-based coding. Still it is possible:
P4OUT ^= BIT7;
The code begins with GPIO settings as follows:
GPIO_setAsOutputPin (GPIO_PORT_P1, GPIO_PIN0);
GPIO_setDriveStrength(GPIO_PORT_P1, GPIO_PIN0, GPIO_FULL_OUTPUT_DRIVE_STRENGTH);
GPIO_setAsOutputPin (GPIO_PORT_P4, GPIO_PIN7);
GPIO_setDriveStrength(GPIO_PORT_P4, GPIO_PIN7, GPIO_FULL_OUTPUT_DRIVE_STRENGTH);
GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P2, GPIO_PIN1);
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5, (GPIO_PIN2 | GPIO_PIN4));
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P5, (GPIO_PIN2 |
GPIO_PIN4));
Two pins P1_0 and P4_7 are set as outputs with full drive strength since these pins have LEDs
connected with them. P2_1 is set as an input with pull-up as it is connected with an onboard push
button. Some pins of P5 are set for peripheral modules because these pins are connected with external
crystals.
Next, we set to configure the clock system. There are two onboard external crystals – one 32.768kHz
clock crystal and one 4MHz crystal. UCS stands for Unified Clock System. Like the basic clock system
in MSP430G2xxx devices, this a complex network of clock system with lot of options. There are several
internal and external clock sources to clock the main clock, the sub-main clock and the auxiliary clock
signals. Here, I used the external crystal clocks to clock MCLK, SMCLK and ACLK
UCS_setExternalClockSource(32768, 4000000);
UCS_turnOnXT2(UCS_XT2_DRIVE_4MHZ_8MHZ);
UCS_turnOnLFXT1(UCS_XT1_DRIVE_0, UCS_XCAP_3);
UCS_initClockSignal(UCS_MCLK, UCS_XT2CLK_SELECT, UCS_CLOCK_DIVIDER_1);
UCS_initClockSignal(UCS_SMCLK, UCS_XT2CLK_SELECT, UCS_CLOCK_DIVIDER_1);
UCS_initClockSignal(UCS_ACLK, UCS_XT1CLK_SELECT, UCS_CLOCK_DIVIDER_1);