0% found this document useful (0 votes)
8 views3 pages

UART Protocol Tutorial for Simplecortex

This document discusses using UART (Universal Asynchronous Receiver/Transmitter) with the Simplecortex microcontroller to send and receive serial data. It explains how to connect the UART to a serial port, include the necessary libraries, initialize a UART port at a specific baud rate, send data by character or string, and receive incoming data with UART_Getchar(). Examples for different IDEs are also included.

Uploaded by

Algo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

UART Protocol Tutorial for Simplecortex

This document discusses using UART (Universal Asynchronous Receiver/Transmitter) with the Simplecortex microcontroller to send and receive serial data. It explains how to connect the UART to a serial port, include the necessary libraries, initialize a UART port at a specific baud rate, send data by character or string, and receive incoming data with UART_Getchar(). Examples for different IDEs are also included.

Uploaded by

Algo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

BRC-Electronics

UART with the Simplecortex

1. Introduction
UART stands for universal asynchronous receiver/transmitter, or in laymens terms, the
serial port. This tutorial will teach you how to use the serial port to send and receive data
trough a USB to serial converter. To connect the UART to a serial port the Rx from the
Simplecortex has to be connected with the Tx from the serial port and the Tx from the
Simplecortex to the Rx from the serial port. Some sensors also use this interface. The
library and examples can be downloaded here.

2. Includes
The libraries for the microcontroller itself and the variables have to be included to:
#include lpc17xx.h
#include lpc_types.h
For the UART the UART library has to be included:
#include uart.h

3. Write data to UART


To write data to a UART port first the port has to be declared with the
UART[num]_Init(baud); command. Num stands for the UART port that is used, there
are 4 UART ports, port0 to port3. Baud stands for the used baudrate, the most used
value is 9600 but higher speeds are no problem. To use UART2 with a 19200 baudrate
the correct command is:
UART2_Init(19200);
There are two ways to send data, send a byte at a time or send a text string. To send
one byte at a time the command is UART[num]_Sendchar(char to be send); . To send
the character A to UART2 the command is:
UART2_Sendchar(65);
65 is the ASCII code of A, it is also possible to use hexadecimal numbers, 0x41 is equal
to the decimal 65 or the ascii code A.
To send a string of text there is the UART[num]_PrintString("Hello world\r\n");
Command.
When sending a line of text add \r\n on the end to make it jump to a new line

BRC-Electronics

March 12, 2012

Page 1 of 3

BRC-Electronics
UART with the Simplecortex

4. Read data from UART


To read data from a UART port the instruction UART[num]_Getchar();. With this
instruction the Simplecortex waits until data is send trough the Simplecortex with UART.
To receive a byte of data from UART1 the correct code is:
uint8_t databyte;
//declare an 8 bit variable
databyte = UART1_Getchar();
The UART port receives a data byte at a time; therefore an 8 bit variable is used. The
data that has been read is stored in the databyte variable.
An example is included for LPCXpresso and CoIDE.

BRC-Electronics

March 12, 2012

Page 2 of 3

BRC-Electronics
UART with the Simplecortex

Contents
1. Introduction .............................................................................................................................................. 1
2. Includes ..................................................................................................................................................... 1
3. Write data to UART ................................................................................................................................... 1
4. Read data from UART................................................................................................................................ 2

BRC-Electronics

March 12, 2012

Page 3 of 3

You might also like