cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F7 Discovery - having trouble getting the ADC DMA to work

sjpatel1992
Associate II
Posted on July 31, 2015 at 15:25

Hello all,

I have configured the ADC to trigger based on Timer 6 update event every (1/48000) seconds. DMA is used to transfer the ADC conversion to memory. However, when I debug, I see the timer count being incremented, but I don't see any ADC conversion being made or anything in the memory location where it saves the ADC values through DMA. I have used ST's CubeMX to generate the initialization code.

#include ''stm32f7xx_hal.h''
uint16_t ADC3ConvertedValue = 0;
uint16_t ADC_Value = 0;
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc3;
DMA_HandleTypeDef hdma_adc3;
TIM_HandleTypeDef htim6;
/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_ADC3_Init(void);
static void MX_TIM6_Init(void);
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE END PFP */
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC3_Init();
MX_TIM6_Init();
HAL_TIM_Base_Start(&htim6);
HAL_ADC_Start_DMA(&hadc3, (uint32_t*)&ADC3ConvertedValue, 1);
while (1)
{
}
/* USER CODE END 3 */
}

0690X00000605XtQAI.png 0690X00000605aIQAQ.png 0690X00000605aNQAQ.png
1 ACCEPTED SOLUTION

Accepted Solutions
sjpatel1992
Associate II
Posted on August 06, 2015 at 01:04

for anyone with same problem, enabling the DAC clock via __HAL_RCC_DAC_CLK_ENABLE() command before starting the timer solved the issue.

View solution in original post

7 REPLIES 7
Posted on July 31, 2015 at 17:37

You'd think the salient code would be one level below this...

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sjpatel1992
Associate II
Posted on July 31, 2015 at 22:10

What do you mean?

sjpatel1992
Associate II
Posted on August 04, 2015 at 15:11

ok, I have narrowed down the problem a bit. The issue lies with the Timer 6 not triggering the ADC.

I guess I could use the timer interrupt to manually trigger the ADC conversion on overflow (1/48000s), but I would rather like to have it trigger automatically. Any suggestions?

raptorhal2
Lead
Posted on August 05, 2015 at 16:00

There is probably salient code missing for timer configuration. See the ADC Trigger Mode example that comes with the HAL library.

Cheers, Hal

sjpatel1992
Associate II
Posted on August 05, 2015 at 17:58

I had no idea there were more examples in the STM32756G_EVAL folder. I was previously only looking under the STM32746G-Discovery folder, and there is only one ADC_regular_conversion_DMA example. T

Anyways, I looked at the main.c file of the ADC_TriggerMode example and found the following differences:

1. Before starting the timer using the HAL_TIM_Base_Start(&htim) function, they have enabled the DAC clock using __HAL_RCC_DAC_CLK_ENABLE();

2. Under the timer configuration, they had MasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_ENABLE, whereas the  initialization code that was generated by CUBEMX has MasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE

 

 

3. in addition, they have used Timer 2 instead of Timer 6, but that shouldn't really make a difference.

I currently don't have access to the discovery board, but do you think these differences are what's causing timer 6 to not trigger? Thanks for the help.

sjpatel1992
Associate II
Posted on August 06, 2015 at 01:04

for anyone with same problem, enabling the DAC clock via __HAL_RCC_DAC_CLK_ENABLE() command before starting the timer solved the issue.

matthiaswaters9
Associate
Posted on November 11, 2016 at 18:42

I am having the same problem on the nucleo-f746zg board and with the __HAL_RCC_DAC_CLK_ENABLE() it at least seems to do something now. So thanks a lot for sharing!

Still I am wondering what the DAC-Clock has to do with a timer-triggered ADC?! Is this just some mistake in HAL or am I missing something?

I know that the CubeMX tool only provides code for initialisation and you have to add your own code to make the controller do what you want, but shouldn't clock enabling be part of that initialization?