PreviousNext
Write & Read
Help > Peripherals > UART > Write & Read

Writes and/or reads data to/from UART peripheral. If UART is not open, the request fails with ERROR_FAIL.

 

Request

 

NADR

PNUM

PCMD

HWPID

0

1 … n

NADR

0x0C

0x02

?

ReadTimeout

WrittenData

 

ReadTimeout    Specifies timeout in 10 ms unit to wait for data to be read after data is (optionally) written. 0xFF specifies that no data should be read.

WrittenData       Optional data to be written to the UART TX buffer.

 

Response

 

NADR

PNUM

PCMD

HWPID

ErrN

DpaValue

0 n-1

NADR

0x0C

0x82

?

0

?

ReadData

 

ReadData         Optional data read from UART RX buffer if the reading was requested and data is available. Please note that the internal buffer limits a maximum number of bytes to PERIPHERAL_UART_MAX_DATA_LENGTH.

 

Error codes

ERROR_FAIL      UART peripheral is not open.

 

Example 1

 

Write three bytes (0x00, 0x01 and 0x02) to UART, no reading:

         DPA Request (master → slave)
NADR=0x0001, PNUM=0x0C, PCMD=0x02, HWPID=0xFFFF, PData={0xff}(No reading) {0x00,0x01,0x02}(written data)

 

          DPA Response (slave → master)
NADR=0x0001, PNUM=0x0C, PCMD=0x82, HWPID=0xABCD, PData={0x00}(No error), {0x07}(DPA Value)

 

Example 2

 

Write three bytes (0x00, 0x01, and 0x02) to UART, read 4 bytes after 10 ms:

 

         DPA Request (master → slave)
NADR=0x0001, PNUM=0x0C, PCMD=0x02, HWPID=0xFFFF, PData={0x01}(10 ms timeout) , {0x00,0x01,0x02}(written data)

 

         DPA Response (slave → master)

NADR=0x0001, PNUM=0x0C, PCMD=0x82, HWPID=0xABCD,

PData={0x00}(No error),{0x07}(DPA Value),{0xaa,0xbb,x0cc,0xdd}(read data)