//******************************************************************************
// MSP432P401 Demo - eUSCI_A0 UART echo at 9600 baud using BRCLK = 12MHz
//
// Description: This demo echoes back characters received via a PC serialport.
// SMCLK/DCO is used as a clock source and the device is put in LPM3
// Theauto-clock enable feature is used by the eUSCI and SMCLK is turned off
// when theUART is idle and turned on when a receive edge is detected.
// Note thatlevel shifter hardware is needed to shift between RS232 and MSP
// voltagelevels.
//
// Theexample code shows proper initialization of registers
// andinterrupts to receive and transmit data.
// To testcode in LPM3, disconnect the debugger.
//
//
//
// MSP432P401
// -----------------
// /|\| |
// || |
// --|RST |
// | |
// | |
// | P1.3/UCA0TXD|----> PC(echo)
// | P1.2/UCA0RXD|<---- PC
// | |
//
// Wei Zhao
// TexasInstruments Inc.
// October2015 (updated) | June 2014 (created)
// Builtwith Code Composer Studio V6.0
//******************************************************************************
从以上信息我们可以看出,此段例程所要做的事情就是将板载串口配置成9600波特率工作的串口,并原样送回我们发送进去的数据。从示意图中我们可以看出,我们只需要一对收发线即可完成本实验。接下来分析其源代码。
#include "msp.h"
int main(void)
{
WDTCTL =WDTPW | WDTHOLD; // Stopwatchdog timer
CS->KEY= 0x695A; //Unlock CS module for register access
CS->CTL0= 0; // Resettuning parameters
CS->CTL0= CS_CTL0_DCORSEL_3; //Set DCO to 12MHz (nominal, center of 8-16MHz range)
//Select ACLK = REFO, SMCLK = MCLK = DCO
CS->CTL1= CS_CTL1_SELA_2 | CS_CTL1_SELS_3 | CS_CTL1_SELM_3;
CS->KEY= 0; // LockCS module from unintended accesses
//Configure UART pins
P1SEL0 |=BIT2 | BIT3; // set2-UART pin as second function