MSPM0_ValvanoWare  1.0
ECE445L starter code
Files | Macros | Functions
UART

Asynchronous serial communication. More...

Files

file  UART.h
 Initialize UART0.
 

Macros

#define CR   0x0D
 CR is carriage return.
 
#define LF   0x0A
 LF is line feed.
 
#define BS   0x08
 BS is back space.
 
#define ESC   0x1B
 ESC is escape character.
 
#define SP   0x20
 SP is space.
 
#define DEL   0x7F
 DEL is delete.
 

Functions

void UART_Init (void)
 Initialize UART0. More...
 
char UART_InChar (void)
 input from UART0 More...
 
char UART_InCharNonBlock (void)
 non blocking input from UART0 More...
 
void UART_OutChar (char data)
 output character to UART0 More...
 
void UART_OutString (char *pt)
 output string to UART0 More...
 
uint32_t UART_InUDec (void)
 input a number from UART0 More...
 
void UART_OutUDec (uint32_t n)
 output a number to UART0 More...
 
void UART_OutSDec (int32_t n)
 output a signed number to UART0 More...
 
uint32_t UART_InUHex (void)
 input a hex number from UART0 More...
 
void UART_OutUHex (uint32_t number)
 output a hex number to UART0 More...
 
void UART_InString (char *bufPt, uint16_t max)
 input a string from UART0 More...
 
void UART_Fix2 (long number)
 Fixed-point output. More...
 
void UART_Fix3 (uint32_t number)
 
void UART_OutUFix1 (uint16_t n)
 
void UART_InitPrintf (void)
 Initialize UART0 to use printf. More...
 
void UART1_Init (void)
 
char UART1_InChar (void)
 
void UART1_OutChar (char data)
 

Detailed Description

Asynchronous serial communication.

UART pins on the MSPM0G3507
Pin Description
PA10 UART0 Tx to XDS Rx
PA11 UART0 Rx from XDS Tx

Function Documentation

◆ UART_Fix2()

void UART_Fix2 ( long  number)

Fixed-point output.

Output a 32-bit number in 0.01 fixed-point format

Parameters
number32-bit signed number to be transferred, -99999 to +99999
Note
Fixed format, always 7 characters
12345 to " 123.45"
-22100 to "-221.00"
-102 to " -1.02"
31 to " 0.31"
error " ***.**"

Returns
none

◆ UART_InChar()

char UART_InChar ( void  )

input from UART0

Wait for new serial port input

Parameters
none
Returns
char ASCII code for key typed

◆ UART_InCharNonBlock()

char UART_InCharNonBlock ( void  )

non blocking input from UART0

Return new serial port input

Parameters
none
Returns
char ASCII code for key typed or 0 if FIFO empty

◆ UART_Init()

void UART_Init ( void  )

Initialize UART0.

initialize 0 for 115200 baud rate.

  • PA10 = UART0 Tx to XDS Rx
  • PA11 = UART0 Rx from XDS Tx

There are two implementations:

  • UART_Init in UARTbusywait.c implements busy-wait synchronization
  • UART_Init in UARTints.c implements interrupt synchronization
Parameters
none
Returns
none

◆ UART_InitPrintf()

void UART_InitPrintf ( void  )

Initialize UART0 to use printf.

Initialize the UART for 115,200 baud rate (assuming 48 MHz bus clock), 8 bit word length, no parity bits, one stop bit. Calls UART_Init()

Parameters
none
Returns
none

◆ UART_InString()

void UART_InString ( char *  bufPt,
uint16_t  max 
)

input a string from UART0

Accepts ASCII characters from the serial port and adds them to a string until <enter> is typed or until max length of the string is reached. It echoes each character as it is inputted. If a backspace is inputted, the string is modified and the backspace is echoed terminates the string with a null character Calls UART_InChar

Parameters
bufPtis a pointer to empty buffer,
maxis the size of the buffer
Returns
none
Note
Modified by Agustinus Darmawan + Mingjie Qiu –

◆ UART_InUDec()

uint32_t UART_InUDec ( void  )

input a number from UART0

InUDec accepts ASCII input in unsigned decimal format and converts to a 32-bit unsigned number valid range is 0 to 4294967295 (2^32-1)

Parameters
none
Returns
32-bit unsigned number
Note
If you enter a number above 4294967295, it will return an incorrect value Backspace will remove last digit typed

◆ UART_InUHex()

uint32_t UART_InUHex ( void  )

input a hex number from UART0

Accepts ASCII input in unsigned hexadecimal (base 16) format No '$' or '0x' need be entered, just the 1 to 8 hex digits It will convert lower case a-f to uppercase A-F and converts to a 16 bit unsigned number value range is 0 to FFFFFFFF If you enter a number above FFFFFFFF, it will return an incorrect value Backspace will remove last digit typed

Parameters
none
Returns
32-bit unsigned number

◆ UART_OutChar()

void UART_OutChar ( char  data)

output character to UART0

Output 8-bit to serial port

Parameters
datais an 8-bit ASCII character to be transferred
Returns
none

◆ UART_OutSDec()

void UART_OutSDec ( int32_t  n)

output a signed number to UART0

Output a 32-bit number in signed decimal format

Parameters
n32-bit number to be transferred
Returns
none
Note
Variable format 1-10 digits with no space before or after

◆ UART_OutString()

void UART_OutString ( char *  pt)

output string to UART0

Output String with NULL termination

Parameters
ptis pointer to a NULL-terminated string to be transferred
Returns
none

◆ UART_OutUDec()

void UART_OutUDec ( uint32_t  n)

output a number to UART0

Output a 32-bit number in unsigned decimal format

Parameters
n32-bit number to be transferred
Returns
none
Note
Variable format 1-10 digits with no space before or after

◆ UART_OutUHex()

void UART_OutUHex ( uint32_t  number)

output a hex number to UART0

Output a 32-bit number in unsigned hexadecimal format

Parameters
number32-bit number to be transferred
Returns
none
Note
Variable format 1 to 8 digits with no space before or after