User manual
LPCXpresso Experiment Kit - User’s Guide
Page 106
Copyright 2013 © Embedded Artists AB
7.15.1 Lab 14a: Transmitting and Receiving via the UART
Expand the UARTSendChar() function to UARTSendString(uint8_t *pStr)
function (transmits a zero-terminated string – the terminating zero is not transmitted) and
UARTSendBuffer(uint8_t *pBuf, uint16_t length) functions.
Create a small program that makes use of these transmission functions. Also let the program echo
every received character.
Connect the FTDI cable and verify that the program works as intended.
Test to echo a longer string: “Received: x” (where x is the received char) from the LPC111x.
Type characters on the PC terminal program and observe the echoed response from the LPC111x.
Now test to send a series of 100 characters back to back from the PC. This is for example done by
sending a 100 byte long file. Select Send file in the File menu. What will happen?
_____________________________________________________________________________
_____________________________________________________________________________
Every received character results in several characters echoed back to the PC. These echoed
characters will take longer time than the time of the (originally) received character. Characters are
received at full speed (back-to-back) and soon both transmit and received FIFOs will be full. Received
characters will start to be missed.
The solution is flow control. A receiver must be able to inform a transmitter that it must wait for a while
before transmitting more characters. One commonly used software solution for this is called Xon/Xoff
flow control, see: http://en.wikipedia.org/wiki/Software_flow_control for more information. A commonly
used hardware solution is called RTS/CTS flow control, see:
http://en.wikipedia.org/wiki/Flow_control_%28data%29#Hardware_flow_control
7.15.2 Lab 14b: Direct printf() to UART
In exercise Lab 4a-4d, semihosting was explored. In this experiment the printf() output will be sent to
the UART communication channel. Remember that the C runtime library had to be of the correct type
for semihosting to work. Have a look at Figure 21 and make sure the project settings select Redlib
(nohost) as the C runtime library for this exercise. There are hooks in Redlib for directing the printf()-
output to any wanted communication channel – the UART in this case.
The two simple functions below is all that is needed to direct the printf()-output to the UART and also to
let scanf()-input come from the UART.
#include "stdio.h"
#include "uart.h"
...
//use UART for printf
int __sys_write(int iFileHandle, char *pcBuffer, int iLength)
{
UARTSendBuffer((uint8_t *)pcBuffer,iLength); //send data buffer to UART
return iLength;
}
int __sys_readc(void)
{
char c;
UARTReceive((uint8_t*)&c, 1, TRUE);
return (int)c;
}
Place the two functions above in a file called retarget.c.