Inputs: None (receives from hardware UART peripheral)
Outputs:
| Port Name | Data Type | Size | Description | Optional |
|---|---|---|---|---|
| Nbr | uint8/uint16 | Scalar | Number of bytes received (buffer fill level) | Yes (enable via Flag_Out parameter) |
| Rx | uint8 | Scalar or Vector [N] | Received data (configurable size) | No (always present) |
The block outputs uint8 data values directly from the UART receive buffer.
| Output Type | Range | Description |
|---|---|---|
| uint8 | 0 to 255 | Raw received byte data |
Note: Output vector size is configurable via Rx_Size parameter or can be automatically determined based on baud rate and sample time.
| Family | Series | Architecture ID | Implementation Files |
|---|---|---|---|
| dsPIC | 30F, 24F, 33F, 33E, 33C, 33A | 1, 2, 3, 4, 8 | PIC bare, Interrupt (Circular Buffer) |
| PIC32 | MK, MZ, MX, PIC32A | Included in dsPIC arch | Same as dsPIC (PIC implementations) |
| SAM E7x/S7x | SAME70, SAMS70, V71, PIC32CZ MC70 | 5 | SAMx7 bare, Interrupt, DMA ping-pong |
| SAM E5x/D5x | SAME5x, SAMD5x | 6 | SAMx5 bare, Interrupt, DMA ping-pong |
| SAM C2x/D2x | SAMC2x, SAMD2x, SAMDA1 | 7 | SAMx5 implementations (shared) |
| Parameter | Options | Description |
|---|---|---|
| Rx_Size_popup | User defined | Inherited via back propagation |
| Rx_Size | Positive integer or [] | User-defined size (when Rx_Size_popup = “User defined”) |
Explicitly set output vector size:
Rx_Size = 1: Scalar output (single byte)Rx_Size = N: Vector output [N x 1]Rx_Size = []: Treated as “Inherited via back propagation”Output size determined by connected downstream block requirements. Simulink propagates size backward from output port connection.
Automatically calculate optimal buffer size based on:
Formula:
Rx_Size = ceil((Baud_Rate / 10) * Sample_Time) + Buffer_Margin
| Parameter | Options | Description |
|---|---|---|
| Flag_Out | On/Off checkbox | Enable ‘Nbr’ output port (number of bytes received) |
| OutputDefault_popup | Fill-in output vector with specified value | Add one trailing 0 |
| OutputDefault | Numeric value (e.g., 0, 255) | Fill value when OutputDefault_popup = “Fill-in” |
OutputDefaultReception behavior depends on the implementation mode selected in the UART Config block:
| Mode ID | Implementation | Description | Hardware FIFO |
|---|---|---|---|
| 0 | Not Configured | RX disabled in UART Config | N/A |
| 1 | Bare (Simplest) | Direct read from hardware FIFO/buffer | 1/4/8 bytes (device dependent) |
| 2 | Circular Buffer | Software buffer with interrupt-driven reception | Plus user-defined circular buffer |
| 3 | DMA Ping-Pong | Two DMA buffers alternating (SAM only) | DMA with ping-pong buffers |
| 4 | DMA Single Buffer | Not implemented for RX | N/A |
Add UART Config block (configure for UART 1, Circular Buffer Rx)
Add UART Rx block
Configure UART Rx:
UART Module: 1
Rx_Size_popup: “User defined”
Rx_Size: 10
Flag_Out: On (monitor bytes received)
OutputDefault_popup: “Fill-in output vector with specified value”
OutputDefault: 0
Connect Rx output [10x1] to downstream processing
Monitor Nbr output to see actual bytes received (0-10)
UART Config: UART 1, 115200 baud, Circular Buffer (256 bytes)
UART Rx block:
UART Module: 1
Rx_Size_popup: “Inherited via internal rule”
SampleTime: 0.01 (10 ms)
Block automatically calculates:
Baud throughput: 115200 / 10 = 11520 bps
Bytes per sample: (11520 * 0.01) / 8 ≈ 144 bytes
Configure UART Rx:
Rx_Size_popup: “User defined”
Rx_Size: 64 (max string length)
Flag_Out: On
OutputDefault_popup: “Add one trailing 0”
Received string automatically null-terminated
Use Nbr output to find actual string length
Compatible with C string functions
UART Rx configuration:
Rx_Size_popup: “Inherited via back propagation”
Rx_Size: [] (or any value, ignored)
Connect Rx output to a block requiring [20x1] input
Simulink automatically sets Rx port size to [20x1]
No manual sizing needed
Reads directly from hardware FIFO:
data[i] = U%RXREG; /* Direct read from receive register */
If no UART Config block is found for the selected UART:
Problem: Rx output size doesn’t match downstream block requirements.Solutions:
Problem: UART Rx block present but Rx output always zero/empty.Solutions:
Problem: Some bytes missing from received data.Solutions:
Problem: Rx output vector has unexpected values in unused positions.Solutions:
[Communication Blocks] | [UART Config] | [UART Tx] | Code Generation