1.2.6.1 How the Library Works

USI service is a wrapper that provides the interface between the Smart Energy stacks and the serial communications channel (UART or USB CDC).

For USI message transmission, SRV_USI_Send_Message function is provided, which packs the data into USI frame format and sends the message through serial interface.

For USI message reception, the service unpacks the data and passes it through callback (SRV_USI_CallbackRegister) to the corresponding client depending on the USI protocol.

In the other side of the serial interface, a similar implementation is needed in an external device to pack/unpack USI messages for the corresponding USI protocol. Microchip provides PC tools and Python libraries, which are used to manage different layers of the Smart Energy stacks.

USI Frame Format

The USI frame format is based on the HDLC specification used along with DLMS. The Serial Communications Profile of the Management Plane defined in the PRIME specification also uses the same format. Below is the structure of the USI frame and field description.

Figure . USI Frame Format
USI general frame format
  • 0x7E: Frame start/end identifier.

  • MSG LENGTH: Message payload length in bytes (MESSAGE DATA field).

  • PROTOCOL ID: USI protocol identifier.

  • MESSAGE DATA: Message payload (variable length). The format is defined by each protocol.

  • CRC: Error detection code for the message. The CRC size is defined by each protocol (see the table below). For more information about CRC format, see PLC CRC Service

USI Protocol (SRV_USI_PROTOCOL_ID Enum)PROTOCOL IDCRC size (bits)
SRV_USI_PROT_ID_MNGP_PRIME0x00-0x0732
SRV_USI_PROT_ID_SNIF_PRIME0x1316
SRV_USI_PROT_ID_PHY_SERIAL_PRIME0x1F16
SRV_USI_PROT_ID_PHY0x2216
SRV_USI_PROT_ID_SNIFF_G30x2316
SRV_USI_PROT_ID_MAC_G30x2416
SRV_USI_PROT_ID_ADP_G30x2516
SRV_USI_PROT_ID_COORD_G30x2616
SRV_USI_PROT_ID_PRIME_API0x308

In order to detect the end of the message properly, it is needed to add escape bytes to all fields described above:

  • 0x7E bytes are replaced by 0x7D5E (2 bytes)

  • 0x7D bytes are replaced by 0x7D5D (2 bytes)

This adds overhead and has to be considered when configuring the size of USI service buffers. The size of transmission buffers must be at least twice the size of the biggest message payload used (for the very worst case, all bytes 0x7E or 0x7D).

USI Protocols

Each protocol defines its own frame format for the USI payload data. A specific PC tool or Python library is provided for each protocol.

PHY Sniffer

There are two USI protocols used to communicate with Microchip Hybrid Sniffer Tool, one for PRIME (SRV_USI_PROT_ID_SNIF_PRIME) and one for G3 (SRV_USI_PROT_ID_SNIFF_G3).

For more information, see PLC PHY Sniffer Service.

PLC PHY Serial

There is one USI protocol used to serialize PLC PHY API (SRV_USI_PROT_ID_PHY) and communicate with Microchip PLC PHY Tester Tool or Microchip PLC PHY Python Libraries. The protocol defines different sub-format for G3 and PRIME.

For more information, see PLC PHY Serial Service.