Skip to main content
jlecl.1
Associate III
July 1, 2023
Solved

ADC_DMA in other file than main

  • July 1, 2023
  • 2 replies
  • 1115 views

Dear everyone,

I'm trying to use ADC in DMA mode, inside other file (a library).

My ADC.H

/*
 * ADC.h
 */

#include "stdlib.h"
#include "stdio.h"
#include "string.h"

#include "stm32f1xx_hal.h"
#include "stm32f1xx_hal_conf.h"
//-----------------------------------------

void ADC_init(void);
void ADC_traitement(void);

My ADC.C

/*
 * ADC.c
 *
 */
#include "ADC.h"

extern ADC_HandleTypeDef hadc1;
extern DMA_HandleTypeDef hdma_adc1;

extern volatile uint32_t *pADC_raw_value[14]; 
//---------------------------------------------------------------
void ADC_init()
{
	HAL_ADCEx_Calibration_Start(&hadc1);
	HAL_ADC_Start_DMA(&hadc1, &pADC_raw_value, 14);
}
//---------------------------------------------------------------
void ADC_traitement()
{
}
//---------------------------------------------------------------
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
	ADC_traitement();
}
//----------------------------------------------------------------

The code can be compiled without error but i have a question because, in spide of my value is an pointer AND extern, the value "pADC_raw_value[14]" can't be accessible in my main.
The problem is a problem of C language, the miskate could me enormous, i'm tired sorry...

This topic has been closed for replies.
Best answer by MM..1

And in normal situation is ADC DMA half word no full word. Array need same tye as DMA setup.

Clean is declare array where is filled then in adc.c without extern and in adc.h with extern and without 14.

In main then only include required. Volatile isnt strictly required for DMA, but for mcus with more memory arreas is required attribute placement for dma accessibe RAM area.

2 replies

Graduate II
July 2, 2023

Hello

Dont declare 'pADC_raw_value' as table of 14 pointers, just declare it as 14 item array :

 

//File that decalres the array:
volatile uint32_t pADC_raw_value[14];
//in the other files:
extern volatile uint32_t pADC_raw_value[14];
// DMA Start:
HAL_ADC_Start_DMA(&hadc1, pADC_raw_value, 14);

 

:

 

MM..1
MM..1Best answer
Chief III
July 2, 2023

And in normal situation is ADC DMA half word no full word. Array need same tye as DMA setup.

Clean is declare array where is filled then in adc.c without extern and in adc.h with extern and without 14.

In main then only include required. Volatile isnt strictly required for DMA, but for mcus with more memory arreas is required attribute placement for dma accessibe RAM area.