cancel
Showing results for 
Search instead for 
Did you mean: 

Right way to Enable/Disable/Re-enable ADC?

Rogers.Gary
Senior II

Hello:

There is a significant amount of time between calls to the ADC peripheral and to save power I would like to shut it down. It does not seem the same as setting it up as it has issues running after.

The order it initializes:

MX_ADC1_Init();

HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);                           

HAL_ADC_Start_DMA(&hadc1, (uint32_t*)adcDMABuffer, DMA_SIZE); 

What I am doing to "deinitialize and stop" is the same order going back:

HAL_ADC_Stop_DMA( &hadc1 );

HAL_ADC_Stop( &hadc1 );   

HAL_ADC_MspDeInit(&hadc1);

Then, to get it going again, I perform the iinitialize. However, the interrupt does not run/function. Is this not the correct way to accomplish what I am trying to do? It seems not, I am hoping someone could let me know.

Thanks!

2 REPLIES 2
berendi
Principal

The right way is documented in the ADC functional description chapter of the reference manual.

HAL functions unfortunately lack proper documentation (or just I couldn't find any yet), so you can try blindly calling some functions in some order that have stop or deinit in their names, and when you are tired of that, implement something that follows the reference manual.

Rogers.Gary
Senior II

1 - Yup, HAL documentation *****.

2 - Blindly? I did mention "specific order". White cane is put away lol.

3 - Don't want to register hack at this point if possible, little time.

In any case, got it working. Using HAL_ADC_Stop( &hadc1 );  ends up calling calls the same bits that need to be set in section 16.4.17 of the sacred programming manual. And yes, order is relevant. And don't deinit/reinit.