cancel
Showing results for 
Search instead for 
Did you mean: 

ADC_DMA in other file than main

jlecl.1
Associate III

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...

1 ACCEPTED SOLUTION

Accepted Solutions
MM..1
Chief III

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.

View solution in original post

2 REPLIES 2
JTP1
Lead

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
Chief III

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.