Skip to main content
ADynr.1
Associate II
February 20, 2023
Question

How can I trigger ADC with an external clock generator?

  • February 20, 2023
  • 1 reply
  • 1453 views

Hello,

I'm trying to trigger ADC on the STM32F303RE Nucleo board with an external clock generator. Without external trigger settings, it works. I changed the trigger source to Timer8, then in TIM8 settings, I chose External Clock Source. What am I doing wrong? I didn't change any user codes, should I add pin up/down commands to start ADC in user code sections?

My ADC(DMA) and TIM8 settings:

(My clock(square wave) generator connected to PB6 pin)

0693W00000aHAcSQAW.png0693W00000aHAchQAG.png

This topic has been closed for replies.

1 reply

S.Ma
Principal
February 20, 2023

If the goal is to trigger an ADC sample conversion, the ADC uses the internal clock AND a GPIO as triggering a conversion which is fed by the external clock.

Use a DMA to store the ADC results into a cyclic RAM array so you can see easily what's happening with less SW coding.

ADynr.1
ADynr.1Author
Associate II
February 20, 2023

I save the data to a size of 12000 buffer, then write in serial port. Without external trigger settings, it works. But, when I change "Continous Conversion Mode-Disable, External Trigger Source-Timer8", it doesn't work.

Briefly, the code I use(some of the variables are for saving to an SD card):

#define ADC_BUF_LEN 12000
 
void myprintf(const char *fmt, ...) {
 static char buffer[ADC_BUF_LEN];
 va_list args;
 va_start(args, fmt);
 vsnprintf(buffer, sizeof(buffer), fmt, args);
 va_end(args);
 
 int len = strlen(buffer);
 HAL_UART_Transmit(&huart2, (uint64_t*)buffer, len, -1);
 
}
 
HAL_ADC_Start_DMA(&hadc1, (uint16_t*)adc_buf, ADC_BUF_LEN);
 
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
	for (int i = 0; i < ADC_BUF_LEN; ) {
	myprintf("%i\r\n", adc_buf[i]);
	i++;
	}