SimpleLink MSP432 - enhanced Universal Serial Communication Interface (eUSCI) - UART Mode | In order you can using MSP432P401R microcontroller chip to build your own embedded systems application, you have to know about the detail features of this microcontroller chip and how to use its. On today article, I will try to explain for you about one communication feature of the SimpleLink MSP432P401R microcontroller chip, i.e. Enhanced Universal Serial Communication Interface (eUSCI) - UART Mode. Understanding the serial communication feature of this microcontroller chip is an important thing for you when you will build embedded systems application which need make serial communication (UART mode) between your system hardware with an external device via TXD and RXD communication line. 

Quote the explanation of eUSCI (UART Mode) on MSP432P401R microcontroller from its technical reference manual document, there are mentioned that the enhanced universal serial communication interface A (eUSCI_A) supports multiple serial communication modes with one hardware module. 

The eUSCI modules are used for serial data communication. The eUSCI module supports synchronous communication protocols such as SPI (3-pin or 4-pin) and I2C, and asynchronous communication protocols such as UART, enhanced UART with automatic baud-rate detection, and IrDA (Infrared Data Association)
  • The eUSCI_An module provides support for SPI (3-pin or 4-pin), UART, enhanced UART, and IrDA. 
  • The eUSCI_Bn module provides support for SPI (3-pin or 4-pin) and I2C. 
  • The MSP432P401x MCUs offer up to four eUSCI_A and four eUSCI_B modules. 
On this article, the explanation will discuss the operation of the asynchronous UART mode only. For the another eUSCI mode (SPI and I2C mode), I will discuss on the separate articles on this website. 

1. eUSCI_A Overview 
The eUSCI_A module supports two serial communication modes: 
  • UART mode 
  • SPI mode 
2. eUSCI_A Introduction (UART Mode) 
In asynchronous mode, the eUSCI_Ax modules connect the device to an external system through two external pins, UCAxRXD and UCAxTXD. UART mode is selected when the UCSYNC bit is cleared. UART mode features include: 
  • 7-bit or 8-bit data with odd, even, or no parity 
  • Independent transmit and receive shift registers 
  • Separate transmit and receive buffer registers 
  • LSB-first or MSB-first data transmit and receive 
  • Built-in idle-line and address-bit communication protocols for multiprocessor systems 
  • Programmable baud rate with modulation for fractional baud-rate support 
  • Status flags for error detection and suppression 
  • Status flags for address detection 
  • Independent interrupt capability for receive, transmit, start bit received, and transmit complete 
Figure 1 shows the eUSCI_Ax block diagram when configured for UART mode. 

Figure 1. eUSCI_Ax Block Diagram - UART Mode (UCSYNC = 0) 

3. eUSCI_A UART Registers 
From the MSP432P401R microcontroller technical reference manual document (Page 922-932), you will get information about the eUSCI_A - UART register. Below are the registers which will involve when you configure the eUSCI_A - UART mode of MSP432P401 microcontroller: 
  1. CAxCTLW0 (eUSCI_Ax Control Word Register 0) 
  2. CAxCTLW1 (eUSCI_Ax Control Word Register 1) 
  3. UCAxBRW (eUSCI_Ax Baud Rate Control Word) Register 
  4. UCAxMCTLW (eUSCI_Ax Modulation Control Word) Register 
  5. UCAxSTATW (eUSCI_Ax Status) Register 
  6. UCAxRXBUF (eUSCI_Ax Receive Buffer) Register 
  7. UCAxTXBUF (eUSCI_Ax Transmit Buffer) Register 
  8. UCAxABCTL (eUSCI_Ax Auto Baud Rate Control) Register 
  9. UCAxIRCTL (eUSCI_Ax IrDA Control Word) Register 
  10. UCAxIE (eUSCI_Ax Interrupt Enable) Register 
  11. UCAxIFG (eUSCI_Ax Interrupt Flag Register) 
  12. UCAxIV (eUSCI_Ax Interrupt Vector) Register 
Note X = The UART number (0, 1, or 2) 

For more information about the registers detail, you can read the SimpleLink MSP432P401R microcontroller datasheet, click here! 

4. eUSCI_A Operation (UART Mode) 
The eUSCI_A (UART Mode) are configured with user software. The setup and operation of the eUSCI_A (UART Mode) are discussed in the following sections. From the SimpleLink MSP432P4xx Technical Reference Manual, the recommended operation steps to Initialize or reconfigure the eUSCI_A module (UART mode) can be explain as follow: 

Step 1: Set UCSWRST with software (UCSWRST = 1). 
Step 2: Initialize all eUSCI_A registers when UCSWRST = 1. 
Step 3: Configure UART ports (UART line, i.e. UCAxTXD and UCAxRXD). 
Step 4: When you have finished reconfigure the UART registers, clear UCSWRST with software (UCSWRST = 0) 
Step 5: Enable interrupts with UCRXIE or UCTXIE (This is optional). 

Below is the example code in UART2 initialization: 

Program 1: UART2 initialization code

Below are the “Program 1” detail explanation. 
EUSCI_A2->CTLW0 |= 1; // UCSWRST = 1, UART on reset mode
The first line instruction of UART2_init function block will make the UART stay on Reset mode, so we can configure/modify the others eUSCI_A UART registers before use it on this mode. 

The eUSCI_A can be reset by a hard-reset or by software-reset (Set the UCSWRST bit to high logic, 1). After a hard/soft reset, the UCSWRST bit is automatically set, keeping the eUSCI_A in a reset condition. On this reset condition, the UCTXIFG bit will be set automatically and resets the UCRXIE, UCTXIE, UCRXIFG, UCRXERR, UCBRK, UCPE, UCOE, UCFE, UCSTOE, and UCBTOE bits. The configuring and reconfiguring of the eUSCI_A module should be done when UCSWRST is set to avoid unpredictable behavior. 
EUSCI_A2->BRW = 26; //3,000,000/115200 = 26 (N= Required division factor)
UCA2BRW is a register that have function to control the UART serial communication baud rate. From the program information, we know that the UART system clock frequency is 3 MHz (equivalent with 3.000.000 Hz) and the expected UART baud rate is 115200, so this instruction will give 26 as the UCBR2 bit value on UCA2BRW register (N = 3.000.000/115200). The 26 is the baud rate N division factor. To get division factor value (N), the formula as follow:

N              = Division factor 
fBRCLK       = UART system clock frequency 
Baud rate = The expected UART Baud rate value 
EUSCI_A2->MCTLW = 1; //Because N>16 so UCOS16 = 1 / Enable oversampling
This instruction will make the UCOS16 bit condition of the MCTLW register become high-logic (1). Because of the division factor (N) of the UART systems clock frequency is bigger than 16, based on the SimpleLink MSP432P401R Technical reference (Page 915), this condition recommended to use the oversampling baud-rate generation mode.
EUSCI_A2->CTLW0 = 0x0081; // 1 stop bit, no parity, SMCLK, 8-bit data
This instruction is an example method in 16-bit register addressing. This instruction function is to set the UART specification with reconfigure the CTLW0 register. 

Figure 2. UCAxCTLW0 Register 

0x0081 is a 16-bit hexadecimal number. To make easy to understand how to address the UCAxCTLW0 register, we should convert this hexadecimal number to 16-bit binary number, so it will be: 

0x0081 = 0b 0000-0000-1000-0001 

The far-right bit is the least significant bit (LSB), vice versa the far-left bit is the most significant bit (MSB) 

With the binary number, we can know the UART specification from the addressed bits of the UCAxCTLW0 register by saw the table 1 below (See the configuration on “Value” column). 

Tabel 1. UCAxCTLW0 register reconfiguration 

From table 1 above, we know the UART specification as follow: 
Bit parity                                       : No parity 
Character length                            : 8-bit data 
Stop bit                                          : 1 stop bit 
UART mode                                  : Synchronous 
Baud rate source clock (BRCLK)     : SMCLK 
P3->SEL0 |= 0x0C; // Configure P3.2(RXD) and P3.3(TXD) as UART line
P3->SEL1 &= ~0x0C;
This instruction will set the P3.2 and P3.3 as the serial communication (UART mode) line. So to build a serial communication with MSP432P401R microcontroller, the external hardware must be connected to that pins. 
EUSCI_A2->CTLW0 &= ~1; // UCSWRST = 0, UART out of reset mode
This instruction will make the UART out of reset mode, so we can’t configure/modify the others eUSCI_A UART registers again. 


Share on Google Plus

About Taufiq D.S. Suyadhi

    Blogger Comment
    Facebook Comment


Post a Comment