UART Rx Block
UART Rx block allows receiving characters on UART

Note: In order to use the UART Rx block in a Simulink® model, it is necessary to first include and set up the UART Configuration block .

The UART Rx block allows receiving one byte through the UART. Received characters might be buffered depending on the UART configuration. The UART Ref selected must be configured using a UART Configuration block. Multiple instances of this block can be used in one Simulink model.

Click image to enlarge.
UART Rx: Main tab

The number of characters received can be set as an output parameter by enabling the option Output Number of char read. The Vector Output size can be set to one of three options available.

If the vector output size is set to User defined with a value greater than one, the Split and Fill-in output vector when not full options become available.

The Inherit via back propagation option sets the size of the output buffer equal to the input size of the block that reads the Rx buffer.

The Inherit via internal rule option sets the Rx output buffer size depending on the sample time of the model, the sample time of the UART Rx block, and the baud rate specified in UART Configuration block.

Click image to enlarge.
UART Tx: Output tab

For example, having a model with a sample time of 1 ms, UART Rx block sample time of 10 ms, and a UART baud rate of 115200, the Rx vector output size will be set to 116 bytes. UART Configuration block displays the number of bytes/step. In this example this number is equal to 11.51bytes/1ms.

Note: When the Vector Output size is set to the User defined option, make sure that the Rx buffer can accommodate the number of characters received relative to the sample time specified for the UART Rx block. One easy way to overcome this situation is to always use the option Inherit via internal rule.

All characters received through the UART can be read, including special characters when Read all received characters is selected. The other option is to stop reading when one specific character is received by selecting the option Stop reading when one specified char is detected followed by the split-character value specified in the Stop reading on character field.

When the output vector is not full, a padding value can be specified from the Fill-in output vector when not full list:

The Fill-in output vector with specified value option will pad the rest of the output vector with the character value specified. There is also one predefined negative value that can be specified: "-1" pads the rest of the output vector with the value of the last received character.

The Add one trailing 0 option will add the NUL character at the end of the output vector, transforming the vector into a string to allow easy integration with string manipulation functions.

The Do nothing option does not pad the rest of the output vector with a specific value. In the latter case, the end of the output buffer is undefined since it contains both new and old characters without a delimiter in between. In this case, the Output Number of char read option can be used to determine how many newly received characters are in the output buffer.

UART Rx example:

The following example echoes the characters received on the UART. A complete UART example can be found in the "UART Terminal Example" page.

UART Rx example
© 2019 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.