Asynchronous and Synchronous Transmission of Uart Data

Thread Starter

Vihaan@123

Joined Oct 7, 2025
234
I wanted to know the difference between synchronous and asynchronous way of UART data transmission. The synchronous or blocking Uart transmission is i assume is something like below
Code:
void Blockng_SendData(uint8_t *data, uint8_t len)
{
    uint8_t index=0;
    while(len-- != 0)
    {
        local_tx_buffer[index++] = *data++;
        UART1_Write(*data);               
    }
}
I am confused with Asynchronous transmission
Code:
static uint8_t local_tx_buffer[20];
void AsynchSendData(uint8_t *data, uint8_t len)
{
      static uint8_t index=0;
        local_tx_buffer[index++] = *data++;
        UART1_Write(*data);               
}
But what is the periodicity at which i shall be calling the function AsynchSendData(), if i have to send some 10 characters. If i am using interrupt based UART transmission.
 

BobTPH

Joined Jun 5, 2013
11,513
You are confusing two independent concepts:

Synchronous vs asynchronous

and

Blocking vs non-blocking

All four combinations can be used.

Synchronous data transmission requires two signals, data and clock. The data is set up by the sender when the clock is in one state, and read by the receiver when the clock is in the opposite state. The rate at which bits are sent does not have to be agreed upon and can even vary from bit to bit. The clock signal tells the receiver when the next bit is available.

Asynchronous data transmission does not use a clock signal. The single data line has an inactive state called “space” and an active state called “mark”, and a bit rate that must be agreed upon by the sender and receiver. A transmission starts when the sender sets the data line to mark for one or two clock periods. After that, each bit is sent for one period until the agreed upon number of bits have been sent. After that the sender sets the data line to space for an agreed upon number of periods.

Blocking and non-blocking refer to the way the program handles the transmission and has nothing to do with the what is seen on the line. Non-blocking code generally uses interrupts to tell the sender that another byte can be sent or the receiver that another byte has been received. The actual transmission of the bits is done by hardware outside the flow of the program.
 

Thread Starter

Vihaan@123

Joined Oct 7, 2025
234
Ok. Thank you, now i understand better
Code:
void Blockng_SendData(uint8_t *data, uint8_t len)
{
    uint8_t index=0;
    while(len-- != 0)
    {
        local_tx_buffer[index++] = *data++;
        UART1_Write(*data);              
    }
}
Is this blocking code as i am waiting in the while loop? Is my understanding correct? How do i make it non blocking if in case it is blocking code? UART1_Write() in turn sets the interrupt for transmission.
 

Thread Starter

Vihaan@123

Joined Oct 7, 2025
234
Ok i was really of the impression that while() is called blocking code.
Code:
static uint8_t txQueue[UART1_CONFIG_TX_BYTEQ_LENGTH];
static uint8_t rxQueue[UART1_CONFIG_RX_BYTEQ_LENGTH];
void UART1_Write( uint8_t byte)
{
    while(UART1_IsTxReady() == 0)
    {
    }

    *txTail = byte;

    txTail++;
    
    if (txTail == (txQueue + UART1_CONFIG_TX_BYTEQ_LENGTH))
    {
        txTail = txQueue;
    }

    IEC0bits.U1TXIE = 1;
}
bool UART1_IsTxReady(void)
{
    uint16_t size;
    uint8_t *snapshot_txHead = (uint8_t*)txHead;
    
    if (txTail < snapshot_txHead)
    {
        size = (snapshot_txHead - txTail - 1);
    }
    else
    {
        size = ( UART1_CONFIG_TX_BYTEQ_LENGTH - (txTail - snapshot_txHead) - 1 );
    }
    
    return (size != 0);
The above is the MCC code generated of PIC. Does
while(UART1_IsTxReady() == 0)
{
}
is called blocking?
 

BobTPH

Joined Jun 5, 2013
11,513
Yes, that is blocking, meaning it waits until the UART is ready for the next character.

Non-blocking code would put the character in a buffer and return immediately (assuming the buffer is not full.) Then an interrupt routine would get control when the UART was ready and pull the first character out of the buffer. This is far more complicated, but necessary when there are other things that need to be done while waiting for the UART.
 
Last edited:
Top