UART Tx Block Icon
UART_Tx Block Icon The UART Tx block transmits data through a configured UART module. This block sends 8-bit data (uint8 type) and supports variable-length transmission with optional feedback on bytes sent. It works in conjunction with the UART Config block to provide flexible, efficient serial transmission.

Block Inputs/Outputs

Inputs:

Port NameData TypeDescriptionOptional
Nuint8/uint16Number of bytes to send (variable length mode)Yes (enable via parameter)
Txuint8 (vector or scalar)Data to transmitNo (always present)
$anyFunction-Call input (triggers execution)Yes (based on ordering)

Outputs:

Port NameData TypeDescriptionOptional
Nuint8/uint16Number of bytes actually sentYes (enable via parameter)
$function-callFunction-Call output (execution chain)Yes (based on ordering)

Block Input/Output Datatype

The block accepts and outputs uint8 data values for UART transmission.

I/O TypeRangeDescription
uint8 (input)0 to 255Raw byte data to transmit
uint8/uint16 (N output)0 to buffer sizeNumber of bytes successfully sent

Supported Device Families

FamilySeriesArchitecture IDImplementation Files
dsPIC30F, 24F, 33F, 33E, 33C, 33A1, 2, 3, 4, 8PIC bare, Interrupt, DMA variants
PIC32MK, MZ, MX, PIC32AIncluded in dsPIC archSame as dsPIC (PIC implementations)
SAM E7x/S7xSAME70, SAMS70, V71, PIC32CZ MC705SAMx7 bare, Interrupt, DMA ping-pong
SAM E5x/D5xSAME5x, SAMD5x6SAMx5 bare, Interrupt, DMA ping-pong
SAM C2x/D2xSAMC2x, SAMD2x, SAMDA17SAMx5 implementations (shared)

Configuration Parameters

UART Selection

  • UART Module - Select UART/USART number (must match UART Config block)
  • Dropdown automatically populated with available UARTs from selected chip

Data Transmission Options

ParameterOptionsDescription
NSend InputOn/Off checkboxEnable ‘N’ input port for variable-length transmission
NSend OutputOn/Off checkboxEnable ‘N’ output port (bytes actually sent)
UART String ModeOn/Off checkboxWhen enabled: ‘0’ (null character) marks end of string
All or NothingOn/Off checkboxOnly transmit if entire buffer can be sent (no partial sends)

Implementation Modes

Transmission behavior depends on the implementation mode selected in the UART Config block:

Mode IDImplementationDescriptionThread Protection
1Bare (Simplest)Direct write to hardware FIFO (1/4/8 bytes)Optional delay protection
2Circular BufferSoftware buffer with interrupt-driven transmissionCritical section protection
3DMA Ping-PongTwo DMA buffers alternating (no data loss)DMA channel management
4DMA Single BufferSingle DMA buffer (possible data loss if full)DMA channel management
5DMA Circular BufferDMA with circular buffer (same as mode 2)Critical section protection

Thread Protection

The block provides configurable thread protection for multitasking environments:

  • Bit 0: Delay protection for tasks
  • Bit 1: Don’t send from tasks
  • Bit 2-3: Same for asynchronous interrupts
  • Common Values:
  • 0x1: Delay task, don’t care interrupts
  • 0x5: Delay all interrupts
  • 0x9: Delay task, don’t send on interrupts
  • 0xA: Don’t send (disabled)

Usage Examples

Basic Transmission (Fixed Length)

  • Add UART Config block (configure for UART 1, Circular Buffer Tx)

  • Add UART Tx block

  • Configure UART Tx:

  • UART Module: 1

  • NSend Input: Off

  • NSend Output: Off

  • UART String Mode: Off

  • All or Nothing: Off

  • Connect uint8 vector [5x1] to Tx input

  • Build and deploy

Variable Length String Transmission

  • Configure UART Tx block:

  • NSend Input: On

  • NSend Output: On (monitor bytes sent)

  • UART String Mode: On

  • All or Nothing: Off

  • Connect N input with dynamic length (e.g., from lookup table)

  • Connect Tx input with uint8 buffer [maxSize x 1]

  • Monitor N output to verify transmission

High-Reliability Transmission (DMA Ping-Pong)

  • UART Config: Select “DMA Ping-Pong Mode” for Tx
  • UART Tx: Enable “All or Nothing” mode
  • Connect fixed-size data packets
  • Result: No partial transmissions, guaranteed delivery

Implementation Details

Bare Mode (Mode 1)

Writes directly to hardware FIFO: U%TXREG = data[i]; /* Direct write to transmit register */

  • No buffering - immediate transmission
  • Limited to hardware FIFO size (1/4/8 bytes)
  • Fastest response, lowest overhead

Circular Buffer (Mode 2 & 5)

  • Software buffer with head/tail pointers
  • Interrupt-driven: TX interrupt sends next byte when ready
  • Buffer size configurable in UART Config block
  • Thread-safe with critical section protection

DMA Modes (Mode 3 & 4)

  • Ping-Pong: Two buffers alternate (buffer A → DMA → buffer B → DMA…)
  • Single Buffer: One buffer (faster but can lose data if full)
  • DMA channel automatically configured
  • Minimal CPU overhead during transmission

Error Handling

Missing UART Config Block

If no UART Config block is found for the selected UART:

  • Block display shows “MISSING UART X Config”
  • Warning printed to console
  • Compilation error: “UART TX is not configured”

Buffer Overflow

  • Circular Buffer: New data discarded if buffer full
  • DMA Single: Data lost if DMA busy
  • DMA Ping-Pong: Always accepts data (switches buffers)
  • All or Nothing: Entire packet rejected if insufficient space
  • [UART Config] - Configure UART module (required)
  • [UART Rx] - Receive data
  • [UART TxMatlab] - MATLAB interface for testing
  • [UART Brk/Autobaud] - Break detection and autobaud

Troubleshooting

Data Not Transmitting

Problem: UART Tx block present but no data on TX line.Solutions:

  • Verify UART Config block exists for same UART number
  • Check TX pin configuration in UART Config block
  • Verify UART enable (UARTEN bit)
  • Check baud rate matches receiver

Partial Data Loss

Problem: Some bytes missing from transmission.Solutions:

  • Increase buffer size in UART Config (Circular Buffer mode)
  • Switch to DMA Ping-Pong mode (no data loss)
  • Enable “All or Nothing” mode (reject partial sends)
  • Reduce transmission rate or increase UART baud rate

Multitasking Issues

Problem: Data corruption in multitasking model.Solutions:

  • Check thread protection settings in UART Config
  • Ensure only one task writes to same UART
  • Use DMA mode to avoid interrupt conflicts

See Also

[Communication Blocks] | [UART Config] | [UART Rx] | Code Generation