Keil Logo

Serial Interface

Almost all microcontrollers have a serial interface (UART peripheral). The UART is a very simple device to send data to a PC via a terminal emulation program (Hyperterm, TeraTerm) or to another microcontroller. In general, the driver for a UART contains functions to initialize, send, and receive data.

The steps to initialize an UART are:

  • Enable the clock signal for the UART.
  • Configure the Alternate Function to use a UART.
  • Set the baud rate registers.
  • Set the protocol parameters (stop bit, parity).
  • Configure FIFO-buffers.
  • Enable the UART.
  • Read from or write to the UART.

For this example the following steps are required:

  1. Create a new project.
  2. Select the STM32F107VC microcontroller from the Device Database.
  3. Include the files:
    • startup_stm32f10x_cl.s
    • system_stm32f10x_cl.c
    • core_cm3.c
    • Serial.c
    • Retarget.c
  4. Create and add a new file, UART.c, to the project.
  5. Use the code below as a reference.
     * Name:    UART.c
     * Purpose: print a string to UART2
     * Notes:
    #include <stdio.h>
    #include <stm32f10x_cl.h>
    // Import external functions from Serial.c file
    extern void init_serial (void);
      MAIN function
    int main (void) {
      printf ("CMSIS Serial Device Example\r\n");
      while (1) {
  6. Build the project.
  7. Connect a Flash programming utility to the PC and to the board.
  8. Configure µVision for Flash downloading.
  9. Download to Flash and debug the application.
  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.