2023-07-01 01:04 PM
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...
Solved! Go to Solution.
2023-07-02 01:16 AM - edited 2023-07-02 01:40 AM
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.
2023-07-01 11:17 PM - edited 2023-07-01 11:19 PM
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);
:
2023-07-02 01:16 AM - edited 2023-07-02 01:40 AM
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.