cancel
Showing results for 
Search instead for 
Did you mean: 

My ADC reading problem with DMA

MŞent.1
Associate II

Hello, I am working with the STM32F429-DISC1 development board. I am trying to read two adc from one channel. I can't read the code that I could read in the past. The code that worked in the morning is not working now. I may have changed a little. Please help me. My code is at below:

#include "main.h"

#include "cmsis_os.h"

#include "usb_host.h"

ADC_HandleTypeDef hadc1;

DMA_HandleTypeDef hdma_adc1;

CRC_HandleTypeDef hcrc;

DMA2D_HandleTypeDef hdma2d;

I2C_HandleTypeDef hi2c3;

LTDC_HandleTypeDef hltdc;

SPI_HandleTypeDef hspi5;

TIM_HandleTypeDef htim1;

UART_HandleTypeDef huart1;

SDRAM_HandleTypeDef hsdram1;

osThreadId defaultTaskHandle;

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_DMA_Init(void);

static void MX_CRC_Init(void);

static void MX_DMA2D_Init(void);

static void MX_FMC_Init(void);

static void MX_I2C3_Init(void);

static void MX_LTDC_Init(void);

static void MX_SPI5_Init(void);

static void MX_TIM1_Init(void);

static void MX_USART1_UART_Init(void);

static void MX_ADC1_Init(void);

void StartDefaultTask(void const * argument);

#define BufferSize 2

uint32_t adcBuff[BufferSize] = {0};

uint32_t adcData[BufferSize] = {0};

uint16_t convEnd = 0;

uint32_t voltage;

uint32_t current;

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

{

   if(hadc == &hadc1)

   {

      for(int i = 0; i < BufferSize ; i++)

      {

         adcData[i] = adcBuff[i];

      }

      convEnd=1;

   }

}

void ADC_Read()

{

   if(convEnd==1)

   {

      voltage = adcBuff[0];

      current = adcBuff[1];

   }

   convEnd=0;

   HAL_Delay(5);

}

int main(void)

{

 HAL_Init();

 SystemClock_Config();

 MX_GPIO_Init();

 MX_DMA_Init();

 MX_CRC_Init();

 MX_DMA2D_Init();

 MX_FMC_Init();

 MX_I2C3_Init();

 MX_LTDC_Init();

 MX_SPI5_Init();

 MX_TIM1_Init();

 MX_USART1_UART_Init();

 MX_ADC1_Init();

 osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 4096);

 defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);

 osKernelStart();

 HAL_ADC_Start_DMA(&hadc1,(uint32_t *)adcBuff,BufferSize);

 while (1)

 {

    ADC_Read();

 }

}

0693W00000UnAJuQAN.png 

0693W00000UnAJpQAN.png0693W00000UnAJkQAN.png0693W00000UnAJaQAN.png0693W00000UnAIrQAN.png

5 REPLIES 5
MŞent.1
Associate II

Please help me

raptorhal2
Lead

The buffer is being read when the ADC completes conversion of the first channel.

Read when when the DMA count goes to zero.

Can you please explain more detailed?

raptorhal2
Lead

Differences I have seen with the F429DISC1 HAL Library ADC DMA example:

Scan Conversion Mode is Disabled

End of Conversion Selection is Disabled.

Did you modify one or both of those?

Insert a breakpoint in the void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

function to see if this gets executed. If it doesn't, an ADC1_DMA_IRQHandler interrupt handler may be missing.

MŞent.1
Associate II

I was reading adc values with same setting, ı dont know why this is happening.