Atmel Software Framework

Advanced use case - Send a packet of serial data

In this use case, the USART module is configured for:

  • Using USARTD0
  • Baudrate: 9600
  • Character length: 8 bit
  • Parity mode: Disabled
  • Stop bit: None
  • RS232 mode

The use case sends a string of text through the USART.

Setup steps

Prerequisites

  1. System Clock Management (sysclk)

Example code

The following configuration must be added to the project (typically to a conf_uart_serial.h file, but it can also be added to your main application file.):

Note
The following takes SAM3X configuration for example, other devices have similar configuration, but their parameters may be different, refer to corresponding header files.
#define USART_SERIAL &USARTD0
#define USART_SERIAL_BAUDRATE 9600
#define USART_SERIAL_CHAR_LENGTH US_MR_CHRL_8_BIT
#define USART_SERIAL_PARITY US_MR_PAR_NO
#define USART_SERIAL_STOP_BIT false

Add to application initialization:

static usart_serial_options_t usart_options = {
.baudrate = USART_SERIAL_BAUDRATE,
.charlength = USART_SERIAL_CHAR_LENGTH,
.paritytype = USART_SERIAL_PARITY,
.stopbits = USART_SERIAL_STOP_BIT
};
usart_serial_init(USART_SERIAL, &usart_options);

Workflow

  1. Initialize system clock:
  2. Create USART options struct:
    • static usart_serial_options_t usart_options = {
      .baudrate = USART_SERIAL_BAUDRATE,
      .charlength = USART_SERIAL_CHAR_LENGTH,
      .paritytype = USART_SERIAL_PARITY,
      .stopbits = USART_SERIAL_STOP_BIT
      };
  3. Initialize in RS232 mode:

Usage steps

Example code

Add to, e.g., main loop in application C-file:

usart_serial_write_packet(USART_SERIAL, "Test String", strlen("Test String"));

Workflow

  1. Write a string of text to the USART: