cancel
Showing results for 
Search instead for 
Did you mean: 

ADC Regular Conversion Interrupt Example

keebler411
Associate II

I can't get the STM32L07RZ-Nucleo ADC regular conversion interrupt example to work. I'm using the Keil MDK variant. I upload the program, start the debugger and put uwADCxConvertedValue into watch window #1

The doc file says to connect a signal to PA.0 which I think corresponds to A0 on the Arduino header. I connected it to 3.3V and the value of the variable in the watch window does not change. Maybe I'm not using the debugger correctly? Thanks.

2 REPLIES 2

Yes, looks like the right pin

Perhaps breakpoint the IRQ, and see it happening.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
keebler411
Associate II

Yeah I wasn't running the program. For some reason I assumed it would run as soon as I started the debugger. I'm really new to to this platform. So the example works, but I initially had problems transferring the code to my program which has its skeleton generated from stmcube32. The examples do not follow the style of the files generated by stmcube32 so its difficult to take an example and insert it into the generated skeleton. It took me awhile to realize that I had to enable interrupts for the ADC in the configuration before generating code.

So how do I convert multiple channels using interrupts? Does it have something to do with setting channel rank? In the callback how do I know which conversion has completed? Watching uwADC8ConvertedValue I can see that it takes on the values of all three channels but I just need to be able to assign the converted value to the correct variable. Interrupt mode is enabled in main() (not shown) Thanks.

This is the generated adc init code:

/* ADC init function */
static void MX_ADC_Init(void)
{
 
  ADC_ChannelConfTypeDef sConfig;
 
    /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 
    */
  hadc.Instance = ADC1;
  hadc.Init.OversamplingMode = DISABLE;
  hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV1;
  hadc.Init.Resolution = ADC_RESOLUTION_12B;
  hadc.Init.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;
  hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
  hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc.Init.ContinuousConvMode = ENABLE;
  hadc.Init.DiscontinuousConvMode = DISABLE;
  hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc.Init.DMAContinuousRequests = DISABLE;
  hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  hadc.Init.LowPowerAutoWait = DISABLE;
  hadc.Init.LowPowerFrequencyMode = ENABLE;
  hadc.Init.LowPowerAutoPowerOff = DISABLE;
  if (HAL_ADC_Init(&hadc) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }
 
    /**Configure for the selected ADC regular channel to be converted. 
    */
  sConfig.Channel = ADC_CHANNEL_8;
  sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }
 
    /**Configure for the selected ADC regular channel to be converted. 
    */
  sConfig.Channel = ADC_CHANNEL_10;
  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }
 
    /**Configure for the selected ADC regular channel to be converted. 
    */
  sConfig.Channel = ADC_CHANNEL_11;
  if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }
}

This is my callback:

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *AdcHandle) {
  /* Get the converted value of regular channel */
  uwADC8ConvertedValue = HAL_ADC_GetValue(AdcHandle);
}