G2A Many GEOs
SHARE
TWEET

Untitled

a guest Mar 30th, 2020 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void MX_ADC1_Init(void)
  2. {
  3.   ADC_MultiModeTypeDef multimode = {0};
  4.   ADC_ChannelConfTypeDef sConfig = {0};
  5.  
  6.   /** Common config
  7.   */
  8.   hadc1.Instance = ADC1;
  9.   hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
  10.   hadc1.Init.Resolution = ADC_RESOLUTION_12B;
  11.   hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  12.   hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
  13.   hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  14.   hadc1.Init.LowPowerAutoWait = DISABLE;
  15.   hadc1.Init.ContinuousConvMode = DISABLE;
  16.   hadc1.Init.NbrOfConversion = 1;
  17.   hadc1.Init.DiscontinuousConvMode = DISABLE;
  18.   hadc1.Init.NbrOfDiscConversion = 1;
  19.   hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  20.   hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  21.   hadc1.Init.DMAContinuousRequests = DISABLE;
  22.   hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  23.   hadc1.Init.OversamplingMode = DISABLE;
  24.   if (HAL_ADC_Init(&hadc1) != HAL_OK)
  25.   {
  26.     Error_Handler();
  27.   }
  28.   /** Configure the ADC multi-mode
  29.   */
  30.   multimode.DMAAccessMode = ADC_DMAACCESSMODE_DISABLED;
  31.   multimode.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_1CYCLE;
  32.   if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
  33.   {
  34.     Error_Handler();
  35.   }
  36.   /** Configure Regular Channel
  37.   */
  38.   sConfig.Channel = ADC_CHANNEL_0;
  39.   sConfig.Rank = ADC_REGULAR_RANK_1;
  40.   sConfig.SamplingTime = ADC_SAMPLETIME_12CYCLES_5;
  41.   sConfig.SingleDiff = ADC_DIFFERENTIAL_ENDED;
  42.   sConfig.OffsetNumber = ADC_OFFSET_NONE;
  43.   sConfig.Offset = 0;
  44.   if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  45.   {
  46.     Error_Handler();
  47.   }
  48.  
  49. }
  50.  
  51.  
  52. // Inside main...
  53.   HAL_ADC_Start(&hadc1);
  54.   if (HAL_ADC_PollForConversion(&hadc1, 1000000) == HAL_OK)
  55.   {
  56.       ADCValue = HAL_ADC_GetValue(&hadc1);
  57.       *pStorage = ADCValue;
  58.       return true;
  59.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top