Keil Logo

UART Communication

Many microcontrollers provide a standard UART or RS232 serial interface. The µVision3 Debugger simulates the UART interface of a microcontroller and provides three Serial Windows which operate like a terminal. The serial windowsthat opens with View — Serial Window #1 .. #3. These serial windows interact like a terminal.  As an alternative you may direct the serial output even to any available COM port of your computer using the ASSIGN command.

Peripheral Dialog

The dialogs provided in the Peripheral Menu show the current status of the UART in your microcontroller system. In this way you may easily review the communication baudrate and other parameters of your system.

UART Peripheral Dialog

Virtual Simulation Registers (VTREG)

For simulation of UART communication, the µVision3 Debugger implements the following virtual simulation registers (VTREG)

VTREG Description
SxIN The input buffer of serial interface x. You may write 8-bit or 9-bit values to SxIN. These are read by your target program. You may read SxIN to determine when the input buffer is ready for another character. The value 0xFFFF signals that the previous value is completely processed and a new value may be written. Other special values may be used to simulate parity or frame errors.
SxOUT The output buffer of serial interface x. µVision3 copies 8-bit or 9-bit values (as programmed) to the SxOUT VTREG.
SxTIME Defines the baudrate timing of the serial interface x. When SxTIME is 1, µVision3 simulates the timing of the serial interface using the programmed baudrate. When SxTIME is 0 (the default value), the programmed baudrate timing is ignored and serial transmission time is instantaneous.

The VTREG naming conventions SxIN, SxOUT, and SxTIME vary from device to device. Several devices provide more than one UART interface and therefore the VTREG names may be prefixed with S0 or S1. You may use the command DIR VTREG to check the virtual simulation register names of the UART interface of the device you have selected.

Input Characters via the SxIN VTREG

The SxIN VTREG represent the inputs to the on-chip serial port of the microcontroller.

The following Debug Commands (typed in the debugger's Command Window) input a value into the serial stream. Note that you may also use the Serial Window in the µVision3 Debugger to input characters for the serial port.

SIN = 'A'      /* Input the letter A into the serial stream */
SIN = 0x019E   /* Input the 9-bit value 19Ex into the serial stream */
SIN = 0xA9     /* input value 0xA9 to I/O stream for the UART */

Control UART Communication Timing

The SxTIME VTREG allows you to control the timing of the simulated serial port.

  • A value of 1 indicates that the serial port timing is identical to the target hardware. Use this value when you want to see the effects of baud rate on the serial port I/O.
  • A value of 0 indicates that all serial input and output occur instantaneously. Use this value when you don't care about any baud rate effects or when you want serial output to be fast.

For example:

STIME = 0   /* Set Serial 0 for FAST timing */
STIME = 1   /* Set Serial 0 for accurate timing */

UART Simulation Example

The following debug script sends the characters 'A' - 'Z' with a speed of about 19.200 baud.

signal void serialA_Z (void) {
  char ch;

  for (ch = 'A'; ch < 'Z'; ch++)   {
   S0IN = ch;                                // send character
   twatch (CLOCK / 900);
  }                                          /* repeat */
}

Refer to the Support Knowledgebase at www.keil.com/support for an Automated Serial Input Script and other examples.

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.