Keil Logo

UART Communication

UART Communication or RS232 serial interfaces are provided by many microcontrollers. The µVision Debugger simulates the UART interface and provides Serial Windows for communication. Serial Windows operate similar to a terminal. As an alternative, serial output can be redirected to any COM port using the ASSIGN command.

Peripheral Dialog

UART or Serial dialogs provided through the menu Peripherals show the serial interface status of the microcontroller. These dialogs allow reviewing the communication baudrate and other parameters of the system.

UART Peripheral Dialog

Virtual Simulation Registers (VTREG)

VTREGs that simulate UART communication are implemented as follows:

VTREG Description
SxIN Is the input buffer of serial interface x. SxIN accepts 8- or 9-bit values, which are read by the target program. Read SxIN to determine when the input buffer is ready to accept another character. The special value 0xFFFF signals that the previous value has been processed and a new value can be written. Other special values can be used to simulate parity errors or frame errors.
SxOUT Is the output buffer of serial interface x. µVision copies 8- or 9-bit values (as programmed) to the SxOUT VTREG.
SxTIME Defines the baudrate timing of the serial interface x. When SxTIME is 1, µVision 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 is instantaneous.

The naming conventions for VTREGs (SxIN, SxOUT, and SxTIME) vary from device to device. Several devices provide more than one UART interface. Therefore, the VTREG names might be prefixed with S0 or S1. Use the command DIR VTREG to check the VTREG names of the UART interface.

Input Characters via SxIN VTREG

The SxIN VTREG represent inputs to the on-chip serial port of the microcontroller. The following commands, used from the Command Window, input a value to the serial stream. Also, the Serial Window can be used to input values for the serial port.

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

Control UART Communication Timing

The SxTIME VTREG allows controlling 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 to simulate the implication of the baudrate on the serial port I/O.
  • A value of 0 indicates that serial input and output occurs instantaneously. Use this value when the baudrate is not relevant, or to speed-up serial output.

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 */
}

Note

  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.