UART and USART API Reference#

This guide explains how to use the UART/USART APIs on the SiWx917 platform.
These APIs enable robust and efficient serial communication, supporting both asynchronous (UART) and synchronous/asynchronous (USART) data transfer between devices.

For complete API details, refer to the official documentation:
SiWx917 UART/USART API Reference

Public APIs#

The public APIs allow developers to configure and control serial communication on SiWx917.
Use these APIs to:

  • Initialize UART or USART peripherals.

  • Send and receive data streams.

  • Configure baud rate, parity, stop bits, and data format.

These APIs are ideal for direct serial communication.
For event-driven applications, see the Callback and Notification APIs below.

Callback and Notification APIs#

The callback and notification APIs allow applications to handle UART/USART events efficiently without polling.
Instead of continuously checking status registers, your application registers a callback function that is automatically invoked by the driver when an event occurs—such as transfer completion or an error.

This event-driven approach improves performance and efficiency, allowing the system to respond only when necessary and freeing CPU resources for other tasks.

Callback Function#

A callback function defines how the application responds to UART/USART events.

typedef void (*sl_usart_callback_t)(uint32_t event);

Description

The sl_usart_callback_t type defines a function pointer that the driver uses to notify the application about UART/USART events.

Parameters

  • event (uint32_t, [in]): Event code that identifies the UART/USART event type.

    Possible values include:

    • Send Complete

    • Receive Complete

    • Transfer Complete

Usage

Register the callback during UART/USART initialization or configuration.
The driver automatically invokes this function when an event occurs, allowing the application to process incoming data, signal completion, or update system state as required.

Example

void uart_callback_event(uint32_t event)
{
 switch (event) {
  case SL_USART_EVENT_SEND_COMPLETE:
   uart_send_complete = true;
   break;
  case SL_USART_EVENT_RECEIVE_COMPLETE:
   uart_receive_complete = true;
   break;
  case SL_USART_EVENT_TRANSFER_COMPLETE:
   uart_transfer_complete = true;
   break;
 }
}

Integration#

Integrate the callback into your application by registering it with the driver:

sl_si91x_usart_multiple_instance_register_event_callback(USART_0, usart_callback_event);

After registration, the driver automatically calls the uart_callback_event function whenever an event occurs. This design enables event-driven communication and eliminates the need for manual polling, resulting in improved responsiveness and energy efficiency.