2025-06-03 6:54 AM - last edited on 2025-06-04 4:21 AM by mƎALLEm
Hello!
I am trying to trigger an ADC sample to write to DMA via a timer and trigger a green LED on PB0 after every sample so I can use an oscilloscope to verify the sampling speed. However, I believe after trying to debug as best I can, I do not have the correct configuration for the ADC or there is a problem with the DMA requests. I have included all of the user code that I have placed inside the main.c file at the bottom of this post. I have also included a photo of my ADC settings. I wasn't able to include it but I have enabled the NVIC interrupts by clicking the check boxes.
I can successfully build and flash the code to the device, that is the code I shared. I do not get back any errors during building, its just the LED doesn't flash.
I have ensured the LED is working by just placing a simple toggle code in the while statement and running that.
#define BUFFER_SIZE 2
/* USER CODE BEGIN 2 */
HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET_LINEARITY, ADC_SINGLE_ENDED);
HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adc_buffer, BUFFER_SIZE);
HAL_TIM_Base_Start(&htim1);
/* USER CODE END 2 */
/* USER CODE BEGIN 4 */
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0);
}
/* USER CODE END 4 */
//I have also debugged with the following code in the While Statement
if (adc_buffer[0] > 0)
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);
Thank you for your help!
Solved! Go to Solution.
2025-06-04 4:16 AM - edited 2025-06-04 4:32 AM
Hello @kyleg4032
Please refer to this article as starting point for your application.
Using Timers to Trigger ADC conversions periodical... - STMicroelectronics Community
2025-06-04 4:16 AM - edited 2025-06-04 4:32 AM
Hello @kyleg4032
Please refer to this article as starting point for your application.
Using Timers to Trigger ADC conversions periodical... - STMicroelectronics Community
2025-06-04 7:59 AM
Hello @kyleg4032
Please refer to the example below:
2025-06-04 11:00 AM
Hi @Saket_Om
Thank you for your help on this matter, I have so far been able to successfully get one of my ADC's working via a timer. Overall my project requires two separate ADC's to be working simultaneously off the same trigger source so I am working to expand on the initial example you provided. So far so good, have gotten a signal on my o-scope!
I would like for the values that are converted by the ADC at the timer interval to be sent to DMA/variable buffer so I can then run a regulation scheme on the incoming signals. I will look through what you sent and hopefully I will be able to get the DMA side working as well.
Thank you for your help, as a extremely new person to STM microcontrollers, it helps a ton!
Kyle