Having trouble using DMA to store ADC data in a Timer driven ADC sampling sequence.
Description:
I'm running Timer 3 to produce a continuous PWM output on Channel 1.
I'm also running Timer 1 in slave mode to Timer 3, in PWM one shot mode with the Repetition Counter set to 5 and the Update Event Interrupt enabled.
This causes Timer 1 to produce a stream of 5 pulses on its Channel 1 output after every Update Event on Timer 3.
I'm running ADC 1 in DMA mode with data stored in an array variable.
The ADC is triggered by the 5 Capture/Compare Update events from Timer 1.
The DMA is set up to store the data in an array.
When Timer 1 completes the 5 pulses it issues an Update Event which triggers a Timer Interrupt.
A HAL_TIM_PeriodElapsedCallback(...) is called and a brief output pulse is generated on a GPIO output pin. This can be observed on the oscilloscope.
I use STM Studio to track the values in the data array.
I can vary the ADC input voltage.
Problem:
The data array values remain at zero no matter what the input voltage is set to.
What am I doing wrong?
Relevant Code:
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define Number_of_Samples 5 // Number of ADC samples to collect *** NOTE: Number_of_Samples = TIM1 RCR+1 ***
/* USER CODE END PD */
/* USER CODE BEGIN PV */
uint32_t adc_data[Number_of_Samples]; // Array for collecting raw ADC samples (12 bit)
uint32_t adc_data_sum; // Summation of all 5 values of adc_data
/* USER CODE END PV */
/* USER CODE BEGIN 2 */
HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED);// Calibrate the ADC for both offset and linearity for single ended mode
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&adc_data, Number_of_Samples);// Start the ADC with DMA transfer of the output to the variable "adc_data"
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1); // Start the sampling time base timer
HAL_TIM_PWM_Start_IT(&htim1, TIM_CHANNEL_1); // Start Timer 1 to produce 5 Capture/Compare Output Events that will trigger ADC1 to take a sample
TIM1->DIER=0x1; // This instruction is required to enable Timer 1 Update Event Interrupt because HAL_TIM_PWM_Start_IT doesn't do it
/* USER CODE END 2 */
/* USER CODE BEGIN 4 */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim)
{
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_4, GPIO_PIN_SET); // Create an output pulse for the oscilloscope
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_4, GPIO_PIN_RESET); // Reset the output
}
STM32Cube IDE Set Up for ADC1: