Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 359 of 9365. Communication Protocols and Data TransferFree lesson

Full-Duplex Data Exchange Mechanisms

Execute simultaneous bidirectional data transmission by shifting bits through the master and slave shift registers during every clock cycle.

In this lesson, you will learn how to achieve simultaneous, bidirectional data flow by using the "circular shift register" mechanism inherent in synchronous protocols like SPI.

The Hardware Conveyor Belt

In serial communication, we often think of data moving from Point A to Point B. However, in a full-duplex synchronous system, we treat communication as a simultaneous exchange. Imagine two people standing back-to-back, each holding a stack of eight cards. Every time a bell rings (the clock pulse), they both slide their top card to the other person and receive one in return.

At the hardware level, this is handled by two shift registers—one in the Master and one in the Slave—connected in a ring.

How the Shift Occurs

During every clock cycle, the Master generates a pulse. On the rising or falling edge of this pulse:

  1. The Most Significant Bit (MSB) of the Master's register is pushed out onto the MOSI (Master Out Slave In) line.
  2. Simultaneously, the MSB of the Slave's register is pushed out onto the MISO (Master In Slave Out) line.
  3. Both registers shift their remaining bits to the left, and the incoming bits from the opposite device are "latched" into the empty slots created at the end of the registers.

After eight clock pulses, the two registers have effectively swapped contents.

// Conceptual logic of a full-duplex exchange
uint8_t exchange_byte(uint8_t data_to_send) {
    SPIDataRegister = data_to_send; // Load the outgoing byte
    
    // Hardware shifts 8 bits out and 8 bits in simultaneously
    while (!(SPIStatusRegister & TRANSFER_COMPLETE)); 
    
    return SPIDataRegister; // Retrieve the incoming byte
}

Why it Matters

Because the hardware does this shift in a single clock cycle, the "Master Out" and "Master In" actions occur at the exact same moment. You are never just "sending" or "receiving"; you are always exchanging. Even if you only care about reading data from a sensor, the Master must still send dummy bytes (usually 0x00 or 0xFF) to keep the clock running so the Slave has a "pulse" to push its data onto the MISO line.

Key Takeaway: Full-duplex communication functions like a hardware swap where the Master and Slave shift registers exchange their contents bit-by-bit over a shared clock, meaning every bit sent is synchronized with a bit received.