ADC DMA Driver

The Analog to Digital Converter (ADC) DMA driver uses DMA system to transfer data from ADC to a memory buffer in RAM. User must configure DMAC system driver accordingly. To set memory buffer and its size adc_dma_read function is used. This function programs DMA to transfer the results of input signal conversion to the given buffer. A callback is called when all the data is transfered, if it is registered via adc_dma_register_callback function.

Summary of the API's Functional Features

The API provides functions to:
  • Initialize and deinitialize the driver and associated hardware

  • Select single shot or free running conversion modes

  • Configure major ADC properties such as resolution and reference source

  • Notification via callback about errors and transfer completion

Summary of Configuration Options

Below is a list of the main ADC parameters that can be configured in START. Many of these parameters are used by the adc_dma_init function when initializing the driver and underlying hardware. Most of the initial values can be overridden and changed runtime by calling the appropriate API functions, such as adc_dma_set_resolution.
  • Selecting which ADC input channels to enable for positive and negative input

  • Which clock source and prescaler the ADC uses

  • Various aspects of Event control

  • Single shot or free running conversion modes

  • Sampling properties such as resolution, window mode, and reference source

  • Run in Standby or Debug mode

DMA is a system driver in START and can be enabled and configured there.

Driver Implementation Description

Dependencies

  • ADC hardware with result ready/conversion done and error interrupts

Example of Usage

The following shows a simple example of using the DMA to transfer ADC results into RAM buffer. User must configure DMAC system driver accordingly in START.

The ADC must have been initialized by adc_dma_init. This initialization will configure the operation of the ADC, such as resolution and reference source, etc.

          /* The buffer size for ADC */
          #define ADC_0_BUFFER_SIZE 16
          static uint8_t ADC_0_buffer[ADC_0_BUFFER_SIZE];
          static void convert_cb_ADC_0(const struct adc_dma_descriptor *const descr)
          {
          }
          /**
           * Example of using ADC_0 to generate waveform.
           */
          void ADC_0_example(void)
          {
              adc_dma_register_callback(&ADC_0, ADC_DMA_COMPLETE_CB, convert_cb_ADC_0);
              adc_dma_enable_channel(&ADC_0, 0);
              adc_dma_read(&ADC_0, ADC_0_buffer, ADC_0_BUFFER_SIZE);
          }
        

Dependencies

  • The ADC peripheral and its related I/O lines and clocks

  • The NVIC must be configured so that ADC interrupt requests are periodically serviced

  • DMA