Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 219 of 9363. Microcontroller Fundamentals and Bare-Metal CFree lesson

Synchronizing DMA Transfers with Peripheral Requests

Use hardware handshake signals to ensure DMA transfers occur only when peripherals have valid data ready for processing.

In this lesson, you will learn how to use hardware handshake signals to ensure DMA transfers occur only when your peripherals have valid data ready for processing.

The Problem of Timing

In previous lessons, we looked at Memory-to-Memory transfers where the DMA controller moves data as fast as the system bus allows. However, when working with peripherals like an ADC (Analog-to-Digital Converter) or a UART, data isn't always sitting in a register waiting to be read. If the DMA attempts to grab data before the peripheral has finished its conversion, you will simply copy stale or invalid information.

Enter Hardware Handshaking

To solve this, modern DMA controllers utilize Hardware Handshaking. Instead of the CPU or the DMA controller "guessing" when data is ready, the peripheral acts as the master of the transaction.

  1. Request Signal (DMAReq): When a peripheral (e.g., an ADC) completes a conversion, it raises a hardware request signal to the DMA controller.
  2. Acknowledge Signal (DMAAck): The DMA controller sees this request, gains control of the bus, performs the read from the peripheral, and asserts an acknowledge signal to tell the peripheral the data has been consumed.

This mechanism ensures that the DMA is perfectly synchronized with the peripheral's internal clock or sampling rate. The CPU remains in a low-power state or continues executing mainline code while the hardware handles the "handshake" automatically.

Conceptual Implementation

You don't manually check if data is ready in your code; instead, you configure the DMA channel to listen to the specific peripheral's request line:

// Example: Concept of assigning a request line to a DMA channel
DMA_Channel_Config(DMA_CH1, REQUEST_SRC_ADC1); // Link ADC1 to Channel 1
DMA_Enable_Peripheral_Requests(DMA_CH1);       // Enable hardware handshake
DMA_Start_Transfer(DMA_CH1, &ADC1->DR, buffer, size);

In this setup, the DMA remains idle until the REQUEST_SRC_ADC1 line is toggled by the ADC hardware. Once triggered, the DMA moves one word and waits for the next hardware trigger. This prevents data loss and eliminates the need for slow, interrupt-driven polling for every single byte of data.

Key Takeaway: Hardware handshaking allows peripherals to pace the DMA controller, ensuring data is moved only when it is valid and ready, effectively removing the CPU from the data-movement loop.