/* ADC1 init function */ void MX_ADC1_Init(void) { ADC_ChannelConfTypeDef sConfig; /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ hadc1.Instance = ADC1; hadc1.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV4; hadc1.Init.Resolution = ADC_RESOLUTION12b; hadc1.Init.ScanConvMode = ENABLE; hadc1.Init.ContinuousConvMode = DISABLE; hadc1.Init.DiscontinuousConvMode = DISABLE; hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc1.Init.NbrOfConversion = 3; hadc1.Init.DMAContinuousRequests = DISABLE; hadc1.Init.EOCSelection = EOC_SINGLE_CONV; HAL_ADC_Init(&hadc1); /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_1; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; HAL_ADC_ConfigChannel(&hadc1, &sConfig); /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_2; sConfig.Rank = 2; HAL_ADC_ConfigChannel(&hadc1, &sConfig); /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_3; sConfig.Rank = 3; HAL_ADC_ConfigChannel(&hadc1, &sConfig); }
/* ADC init function */ 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.ClockPrescaler = ADC_CLOCK_ASYNC; hadc.Init.Resolution = ADC_RESOLUTION12b; hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD; hadc.Init.EOCSelection = EOC_SINGLE_CONV; hadc.Init.LowPowerAutoWait = DISABLE; hadc.Init.LowPowerAutoPowerOff = DISABLE; hadc.Init.ContinuousConvMode = DISABLE; hadc.Init.DiscontinuousConvMode = ENABLE; hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc.Init.DMAContinuousRequests = DISABLE; hadc.Init.Overrun = OVR_DATA_PRESERVED; HAL_ADC_Init(&hadc); /**Configure for the selected ADC regular channel to be converted. */ sConfig.Channel = ADC_CHANNEL_6; sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; HAL_ADC_ConfigChannel(&hadc, &sConfig); sConfig.Channel = ADC_CHANNEL_7; sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; HAL_ADC_ConfigChannel(&hadc, &sConfig); sConfig.Channel = ADC_CHANNEL_8; sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; HAL_ADC_ConfigChannel(&hadc, &sConfig); }
/* ADC init function */ 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_CLOCKPRESCALER_PCLK_DIV1; hadc.Init.Resolution = ADC_RESOLUTION12b; //hadc.Init.SamplingTime = ADC_SAMPLETIME_28CYCLES_5; //hadc.Init.SamplingTime = ADC_SAMPLETIME_41CYCLES_5; hadc.Init.SamplingTime = ADC_SAMPLETIME_239CYCLES_5; hadc.Init.ScanDirection = ADC_SCAN_DIRECTION_UPWARD; hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc.Init.ContinuousConvMode = ENABLE; hadc.Init.DiscontinuousConvMode = DISABLE; hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIG_EDGE_NONE; hadc.Init.DMAContinuousRequests = ENABLE; hadc.Init.EOCSelection = EOC_SEQ_CONV; hadc.Init.Overrun = OVR_DATA_OVERWRITTEN; hadc.Init.LowPowerAutoWait = DISABLE; hadc.Init.LowPowerFrequencyMode = DISABLE; hadc.Init.LowPowerAutoOff = DISABLE; HAL_ADC_Init(&hadc); /**Configure for the selected ADC regular channel to be converted. */ sConfig.Channel = ADC_CHANNEL_0; HAL_ADC_ConfigChannel(&hadc, &sConfig); /**Configure for the selected ADC regular channel to be converted. */ sConfig.Channel = ADC_CHANNEL_1; HAL_ADC_ConfigChannel(&hadc, &sConfig); }
/* ADC1 init function */ void MX_ADC1_Init(void) { ADC_ChannelConfTypeDef sConfig; ADC_InjectionConfTypeDef sConfigInjected; /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ hadc1.Instance = ADC1; hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; hadc1.Init.Resolution = ADC_RESOLUTION_12B; hadc1.Init.ScanConvMode = DISABLE; hadc1.Init.ContinuousConvMode = DISABLE; hadc1.Init.DiscontinuousConvMode = DISABLE; hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc1.Init.NbrOfConversion = 1; hadc1.Init.DMAContinuousRequests = DISABLE; hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV; if (HAL_ADC_Init(&hadc1) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_6; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configures for the selected ADC injected channel its corresponding rank in the sequencer and its sample time */ sConfigInjected.InjectedChannel = ADC_CHANNEL_6; sConfigInjected.InjectedRank = 1; sConfigInjected.InjectedNbrOfConversion = 1; sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_3CYCLES; sConfigInjected.ExternalTrigInjecConvEdge = ADC_EXTERNALTRIGINJECCONVEDGE_RISING; sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJECCONV_T1_TRGO; sConfigInjected.AutoInjectedConv = DISABLE; sConfigInjected.InjectedDiscontinuousConvMode = DISABLE; sConfigInjected.InjectedOffset = 0; if (HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } }
void Adc_Init(){ ADC_ChannelConfTypeDef sConfig; GPIO_InitTypeDef GPIO_InitStruct; /*##-- Enable peripherals and GPIO Clocks #################################*/ /* ADC3 Periph clock enable */ __HAL_RCC_ADC1_CLK_ENABLE(); /* Enable GPIO clock ****************************************/ __HAL_RCC_GPIOC_CLK_ENABLE(); /*##-- Configure peripheral GPIO ##########################################*/ /* ADC3 Channel8 GPIO pin configuration */ GPIO_InitStruct.Pin = GPIO_PIN_3; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); AdcHandle.Instance = ADC1; AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2; AdcHandle.Init.Resolution = ADC_RESOLUTION_12B; AdcHandle.Init.ScanConvMode = DISABLE; AdcHandle.Init.ContinuousConvMode = DISABLE; AdcHandle.Init.DiscontinuousConvMode = DISABLE; AdcHandle.Init.NbrOfDiscConversion = 0; AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1; AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; AdcHandle.Init.NbrOfConversion = 1; AdcHandle.Init.DMAContinuousRequests = DISABLE; AdcHandle.Init.EOCSelection = DISABLE; if(HAL_ADC_Init(&AdcHandle) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /*##-- Configure ADC regular channel ######################################*/ sConfig.Channel = ADC_CHANNEL_13; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; sConfig.Offset = 0; if(HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK) { /* Channel Configuration Error */ Error_Handler(); } }
/** * @brief Configures joystick available on adafruit 1.8" TFT shield * managed through ADC to detect motion. * @retval Joystickstatus (0=> success, 1=> fail) */ uint8_t BSP_JOY_Init(void) { if (ADCx_Init() != HAL_OK) { return (uint8_t) HAL_ERROR; } /* Select Channel 8 to be converted */ sConfig.Channel = ADC_CHANNEL_8; sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; /* Return Joystick initialization status */ return (uint8_t)HAL_ADC_ConfigChannel(&hnucleo_Adc, &sConfig); }
/* ADC2 init function */ void MX_ADC2_Init(void) { ADC_InjectionConfTypeDef sConfigInjected; ADC_ChannelConfTypeDef sConfig; /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ hadc2.Instance = ADC2; hadc2.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2; hadc2.Init.Resolution = ADC_RESOLUTION12b; hadc2.Init.ScanConvMode = ENABLE; hadc2.Init.ContinuousConvMode = DISABLE; hadc2.Init.DiscontinuousConvMode = DISABLE; hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc2.Init.NbrOfConversion = 1; hadc2.Init.DMAContinuousRequests = DISABLE; hadc2.Init.EOCSelection = EOC_SINGLE_CONV; HAL_ADC_Init(&hadc2); /**Configures for the selected ADC injected channel its corresponding rank in the sequencer and its sample time */ sConfigInjected.InjectedChannel = ADC_CHANNEL_13; sConfigInjected.InjectedRank = 2; sConfigInjected.InjectedNbrOfConversion = 0; sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_15CYCLES; sConfigInjected.AutoInjectedConv = DISABLE; sConfigInjected.InjectedDiscontinuousConvMode = DISABLE; sConfigInjected.InjectedOffset = 0; HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected); /**Configures for the selected ADC injected channel its corresponding rank in the sequencer and its sample time */ sConfigInjected.InjectedChannel = ADC_CHANNEL_11; HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected); /**Configures for the selected ADC injected channel its corresponding rank in the sequencer and its sample time */ sConfigInjected.InjectedChannel = ADC_CHANNEL_4; sConfigInjected.InjectedRank = 1; HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected); /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_6; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_144CYCLES; HAL_ADC_ConfigChannel(&hadc2, &sConfig); }
int readAdcChannel(uint32_t channel) { int rtn = -1; HAL_ADC_Init(&hadc); ADC_ChannelConfTypeDef sConfig; static uint32_t channels[3] = {ADC_CHANNEL_7, ADC_CHANNEL_9, ADC_CHANNEL_9}; for (int idx = 0; idx < 3; idx++) { sConfig.Channel = channels[idx]; if (channel == sConfig.Channel) { sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; } else { sConfig.Rank = ADC_RANK_NONE; } HAL_ADC_ConfigChannel(&hadc, &sConfig); } int adcRead[3] = {-1, -1, -1}; for (int i=0; i<3; i++) { if (HAL_ADC_Start(&hadc) == HAL_OK) { if (HAL_ADC_PollForConversion(&hadc, 1000) == HAL_OK) { adcRead[i] = (int)HAL_ADC_GetValue(&hadc); HAL_ADC_Stop(&hadc); } else { HAL_ADC_Stop(&hadc); break; } } else { break; } } if ((adcRead[0] >= 0) && (adcRead[1] >= 0) && (adcRead[2] >= 0)) { rtn = (adcRead[0] + adcRead[1] + adcRead[2])/3; } return rtn; }
/** * @brief CustomHID_Init * Initializes the CUSTOM HID media low layer * @param None * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL */ static int8_t CustomHID_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; ADC_ChannelConfTypeDef sConfig; /* Configure the ADC peripheral */ AdcHandle.Instance = ADCx; /* Configure the ADC clock */ __HAL_RCC_ADC1_CONFIG(RCC_ADC1PCLK2_DIV6); AdcHandle.Init.ScanConvMode = DISABLE; AdcHandle.Init.ContinuousConvMode = ENABLE; AdcHandle.Init.DiscontinuousConvMode = DISABLE; AdcHandle.Init.NbrOfDiscConversion = 0; AdcHandle.Init.ExternalTrigConv = ADC_SOFTWARE_START; AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; AdcHandle.Init.NbrOfConversion = 1; HAL_ADC_Init(&AdcHandle); /* Configure ADC regular channel */ sConfig.Channel = ADCx_CHANNEL; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_7CYCLES_5; HAL_ADC_ConfigChannel(&AdcHandle, &sConfig); /* Start the conversion process and enable interrupt */ HAL_ADC_Start_DMA(&AdcHandle, (uint32_t*)&ADCConvertedValue, 1); /* Configure LED1, LED2, LED3 and LED4 */ BSP_LED_Init(LED1); BSP_LED_Init(LED2); BSP_LED_Init(LED3); BSP_LED_Init(LED4); /* Enable GPIOA clock */ __GPIOA_CLK_ENABLE(); /* Configure PA2 pin as input floating */ GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING_FALLING; GPIO_InitStructure.Pull = GPIO_NOPULL; GPIO_InitStructure.Pin = GPIO_PIN_2; HAL_GPIO_Init(GPIOA, &GPIO_InitStructure); /* Enable and set EXTI2_TSC Interrupt to the lowest priority */ HAL_NVIC_SetPriority(EXTI2_TSC_IRQn, 3, 0); HAL_NVIC_EnableIRQ(EXTI2_TSC_IRQn); return (0); }
void init_adc1(void) { GPIO_InitTypeDef GPIO_InitStruct; //Enable peripheral and GPIO clocks __ADC1_CLK_ENABLE(); __GPIOA_CLK_ENABLE(); //AN0 to AN7 are on PA0 to PA7 //AN0 & 1: 1/10kHz LPF //AN3 & 3: 1/10kHz LPF, 1<G<10 //AN4 & 5: Buffered //AN6 & 7: Resistive dividers, buffered //Config inputs: GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); //ADC1 config: (ToDo: test & optimize, use DMA and multiple conversions) //=========== //Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) hadc1.Instance = ADC1; hadc1.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2; hadc1.Init.Resolution = ADC_RESOLUTION12b; hadc1.Init.ScanConvMode = DISABLE; hadc1.Init.ContinuousConvMode = DISABLE; hadc1.Init.DiscontinuousConvMode = DISABLE; hadc1.Init.NbrOfDiscConversion = 1; hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc1.Init.NbrOfConversion = 1; hadc1.Init.DMAContinuousRequests = DISABLE; hadc1.Init.EOCSelection = EOC_SINGLE_CONV; HAL_ADC_Init(&hadc1); //Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. sConfig.Channel = ADC_CHANNEL_0; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; HAL_ADC_ConfigChannel(&hadc1, &sConfig); //Configure the ADC multi-mode multimode.Mode = ADC_MODE_INDEPENDENT; multimode.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_5CYCLES; HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode); }
//--------------------------------------------------------------------------------- //--------------------------------------------------------------------------------- // // single sample // uint16 uni_adc_singleSample(void) { uint16 val16 = 0; ADC_ChannelConfTypeDef sConfig; //sConfig.Channel = ADC_CHANNEL_VREFINT; sConfig.Channel = ADC_CHANNEL_1; sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES; sConfig.Rank = 1; HAL_ADC_ConfigChannel(&hadc1, &sConfig); if(HAL_ADC_Start(&hadc1) != HAL_OK) return 0; HAL_ADC_PollForConversion(&hadc1, 10); // timeout val16 = HAL_ADC_GetValue(&hadc1); HAL_ADC_Stop(&hadc1); return val16; }
/** * @brief Configures joystick available on adafruit 1.8" TFT shield * managed through ADC to detect motion. * @param None * @retval Joystickstatus (0=> success, 1=> fail) */ uint8_t BSP_JOY_Init(void) { uint8_t status = 1; ADCx_Init(); /* Select the ADC Channel to be converted */ sConfig.Channel = NUCLEO_ADCx_CHANNEL; sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; sConfig.Rank = 1; status = HAL_ADC_ConfigChannel(&hnucleo_Adc, &sConfig); /* Return Joystick initialization status */ return status; }
/** * @brief Configures joystick available on adafruit 1.8" TFT shield * managed through ADC to detect motion. * @param None * @retval Joystickstatus (0=> success, 1=> fail) */ uint8_t BSP_JOY_Init(void) { uint8_t status = 1; ADCx_Init(); /* Start ADC calibration */ HAL_ADCEx_Calibration_Start(&hnucleo_Adc, ADC_SINGLE_ENDED); /* Select Channel 0 to be converted */ sConfig.Channel = ADC_CHANNEL_8; status = HAL_ADC_ConfigChannel(&hnucleo_Adc, &sConfig); /* Return Joystick initialization status */ return status; }
/** * @brief ADC configuration * @param None * @retval None */ static void ADC_Config(void) { ADC_ChannelConfTypeDef sConfig; /* Configuration of ADCx init structure: ADC parameters and regular group */ AdcHandle.Instance = ADCx; AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV4; AdcHandle.Init.Resolution = ADC_RESOLUTION12b; AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; AdcHandle.Init.ScanConvMode = DISABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */ AdcHandle.Init.EOCSelection = EOC_SINGLE_CONV; AdcHandle.Init.LowPowerAutoWait = DISABLE; AdcHandle.Init.ContinuousConvMode = ENABLE; /* Continuous mode to have conversions kept running after 1st conversion trig */ AdcHandle.Init.NbrOfConversion = 1; /* Parameter discarded because sequencer is disabled */ AdcHandle.Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */ AdcHandle.Init.NbrOfDiscConversion = 1; /* Parameter discarded because sequencer is disabled */ AdcHandle.Init.ExternalTrigConv = ADC_SOFTWARE_START; /* Software start to trig the 1st conversion manually, without external event */ AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; AdcHandle.Init.DMAContinuousRequests = DISABLE; AdcHandle.Init.Overrun = OVR_DATA_OVERWRITTEN; if (HAL_ADC_Init(&AdcHandle) != HAL_OK) { /* ADC Initiliazation Error */ Error_Handler(); } /* Configuration of channel on ADCx regular group on rank 1 */ /* Differential mode: only the ADC channel positive has to be configured. */ /* The negative input is configured automatically */ /* Note: Considering IT occuring after each ADC conversion (ADC IT */ /* enabled), select sampling time and ADC clock with sufficient */ /* duration to not create an overhead situation in IRQHandler. */ sConfig.Channel = ADCx_CHANNEL_DIFF_HIGH; sConfig.Rank = ADC_REGULAR_RANK_1; sConfig.SamplingTime = ADC_SAMPLETIME_181CYCLES_5; sConfig.SingleDiff = ADC_DIFFERENTIAL_ENDED; sConfig.OffsetNumber = ADC_OFFSET_NONE; sConfig.Offset = 0; if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK) { /* Channel Configuration Error */ Error_Handler(); } }
uint16_t AdcMcuRead( Adc_t *obj, uint8_t channel ) { ADC_HandleTypeDef *hadc; ADC_ChannelConfTypeDef adcConf; uint16_t adcData = 0; hadc = &obj->Adc; /* Enable HSI */ __HAL_RCC_HSI_ENABLE(); /* Wait till HSI is ready */ while(__HAL_RCC_GET_FLAG(RCC_FLAG_HSIRDY) == RESET) { } __HAL_RCC_ADC1_CLK_ENABLE( ); adcConf.Channel = channel; adcConf.Rank = ADC_REGULAR_RANK_1; adcConf.SamplingTime = ADC_SAMPLETIME_192CYCLES; HAL_ADC_ConfigChannel( hadc, &adcConf); /* Enable ADC1 */ __HAL_ADC_ENABLE( hadc) ; /* Start ADC1 Software Conversion */ HAL_ADC_Start( hadc); HAL_ADC_PollForConversion( hadc, HAL_MAX_DELAY ); adcData = HAL_ADC_GetValue ( hadc); __HAL_ADC_DISABLE( hadc) ; if( ( adcConf.Channel == ADC_CHANNEL_TEMPSENSOR ) || ( adcConf.Channel == ADC_CHANNEL_VREFINT ) ) { HAL_ADC_DeInit( hadc ); } __HAL_RCC_ADC1_CLK_DISABLE( ); /* Disable HSI */ __HAL_RCC_HSI_DISABLE(); return adcData; }
/* ADC1 init function */ void MX_ADC1_Init(void) { ADC_ChannelConfTypeDef sConfig; /**Common config */ hadc1.Instance = ADC1; hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE; hadc1.Init.ContinuousConvMode = ENABLE; hadc1.Init.DiscontinuousConvMode = DISABLE; hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc1.Init.NbrOfConversion = 6; HAL_ADC_Init(&hadc1); /**Configure Regular Channel */ sConfig.Channel = ADC_CHANNEL_11; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_7CYCLES_5; HAL_ADC_ConfigChannel(&hadc1, &sConfig); /**Configure Regular Channel */ sConfig.Channel = ADC_CHANNEL_10; sConfig.Rank = 2; HAL_ADC_ConfigChannel(&hadc1, &sConfig); /**Configure Regular Channel */ sConfig.Channel = ADC_CHANNEL_9; sConfig.Rank = 3; HAL_ADC_ConfigChannel(&hadc1, &sConfig); /**Configure Regular Channel */ sConfig.Channel = ADC_CHANNEL_6; sConfig.Rank = 4; HAL_ADC_ConfigChannel(&hadc1, &sConfig); /**Configure Regular Channel */ sConfig.Channel = ADC_CHANNEL_8; sConfig.Rank = 5; HAL_ADC_ConfigChannel(&hadc1, &sConfig); /**Configure Regular Channel */ sConfig.Channel = ADC_CHANNEL_7; sConfig.Rank = 6; HAL_ADC_ConfigChannel(&hadc1, &sConfig); }
/** * @brief ADC configuration * @param None * @retval None */ static void ADC_Config(void) { ADC_ChannelConfTypeDef sConfig; /* Configuration of ADCx init structure: ADC parameters and regular group */ AdcHandle.Instance = ADCx; AdcHandle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; AdcHandle.Init.Resolution = ADC_RESOLUTION_12B; AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; AdcHandle.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD; /* Sequencer will convert the number of channels configured below, successively from the lowest to the highest channel number */ AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV; #if defined(ADC_LOWPOWER) AdcHandle.Init.LowPowerAutoWait = ENABLE; /* Enable the dynamic low power Auto Delay: new conversion start only when the previous conversion (for regular group) or previous sequence (for injected group) has been treated by user software. */ AdcHandle.Init.LowPowerAutoPowerOff = ENABLE; /* Enable the auto-off mode: the ADC automatically powers-off after a conversion and automatically wakes-up when a new conversion is triggered (with startup time between trigger and start of sampling). */ #else AdcHandle.Init.LowPowerAutoWait = DISABLE; AdcHandle.Init.LowPowerAutoPowerOff = DISABLE; #endif AdcHandle.Init.ContinuousConvMode = DISABLE; /* Continuous mode disabled to have only 1 conversion at each conversion trig */ AdcHandle.Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */ AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_Tx_TRGO; /* Trig of conversion start done by external event */ AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING; AdcHandle.Init.DMAContinuousRequests = ENABLE; AdcHandle.Init.Overrun = ADC_OVR_DATA_PRESERVED; /* Overrun set to data preserved to trig overrun event as an error in this exemple */ if (HAL_ADC_Init(&AdcHandle) != HAL_OK) { /* ADC initialization error */ Error_Handler(); } /* Configuration of channel on ADCx regular group on sequencer rank 1 */ /* Note: Considering IT occurring after each ADC conversion (ADC IT */ /* enabled), select sampling time and ADC clock with sufficient */ /* duration to not create an overhead situation in IRQHandler. */ sConfig.Channel = ADCx_CHANNELa; sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; sConfig.SamplingTime = ADC_SAMPLETIME_41CYCLES_5; if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK) { /* Channel Configuration Error */ Error_Handler(); } }
uint16_t TM_ADC_Read(ADC_TypeDef* ADCx, TM_ADC_Channel_t channel) { ADC_ChannelConfTypeDef sConfig; /* Configure ADC regular channel */ sConfig.Channel = (uint8_t) channel; sConfig.Rank = 1; #if defined(STM32F0xx) || defined(STM32F1xx) sConfig.SamplingTime = ADC_SAMPLETIME_13CYCLES_5; #else sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES; sConfig.Offset = 0; #endif /* Set handle */ AdcHandle.Instance = ADCx; /* Return zero */ if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK) { return 0; } /* Start conversion */ if (HAL_ADC_Start(&AdcHandle) != HAL_OK) { return 0; } #if defined(STM32F0xx) /* Poll for end */ if (HAL_ADC_PollForConversion(&AdcHandle, 10) == HAL_OK) { /* Get the converted value of regular channel */ return HAL_ADC_GetValue(&AdcHandle); } #else /* Poll for end */ HAL_ADC_PollForConversion(&AdcHandle, 10); /* Check if the continous conversion of regular channel is finished */ if (HAL_ADC_GetState(&AdcHandle) == HAL_ADC_STATE_EOC_REG) { /* Get the converted value of regular channel */ return HAL_ADC_GetValue(&AdcHandle); } #endif /* Return zero */ return 0; }
/** * @brief Configures joystick available on adafruit 1.8" TFT shield * managed through ADC to detect motion. * @retval Joystickstatus (0=> success, 1=> fail) */ uint8_t BSP_JOY_Init(void) { if (ADCx_Init() != HAL_OK) { return (uint8_t) HAL_ERROR; } /* Select Channel 15 to be converted */ hnucleo_AdcChannelConfig.Channel = ADC_CHANNEL_15; hnucleo_AdcChannelConfig.SamplingTime = ADC_SAMPLETIME_24CYCLES_5; hnucleo_AdcChannelConfig.Rank = 1; hnucleo_AdcChannelConfig.SingleDiff = ADC_SINGLE_ENDED; hnucleo_AdcChannelConfig.OffsetNumber = ADC_OFFSET_NONE; /* Return Joystick initialization status */ return (uint8_t) HAL_ADC_ConfigChannel(&hnucleo_Adc, &hnucleo_AdcChannelConfig); }
float STM32AdcChannel::GetVoltage () { float result = 0; HAL_ADC_ConfigChannel (adc.adcHandle, &channelConfig); HAL_Delay (1); HAL_ADC_Start (adc.adcHandle); HAL_ADC_PollForConversion (adc.adcHandle, 10); if (HAL_ADC_GetState (adc.adcHandle) == HAL_ADC_STATE_EOC_REG) { result = HAL_ADC_GetValue (adc.adcHandle) * scaleFactor; } return result; }
STATIC void adc_config_channel(ADC_HandleTypeDef *adc_handle, uint32_t channel) { ADC_ChannelConfTypeDef sConfig; sConfig.Channel = channel; sConfig.Rank = 1; #if defined(STM32F4) || defined(STM32F7) sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES; #elif defined(STM32L4) sConfig.SamplingTime = ADC_SAMPLETIME_12CYCLES_5; sConfig.SingleDiff = ADC_SINGLE_ENDED; sConfig.OffsetNumber = ADC_OFFSET_NONE; #else #error Unsupported processor #endif sConfig.Offset = 0; HAL_ADC_ConfigChannel(adc_handle, &sConfig); }
STATIC void adc_config_channel(ADC_HandleTypeDef *adc_handle, uint32_t channel) { ADC_ChannelConfTypeDef sConfig; sConfig.Channel = channel; sConfig.Rank = 1; #if defined(STM32F0) sConfig.SamplingTime = ADC_SAMPLETIME_71CYCLES_5; #elif defined(STM32F4) || defined(STM32F7) sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES; #elif defined(STM32H7) if (channel == ADC_CHANNEL_VREFINT || channel == ADC_CHANNEL_TEMPSENSOR || channel == ADC_CHANNEL_VBAT) { sConfig.SamplingTime = ADC_SAMPLETIME_387CYCLES_5; } else { sConfig.SamplingTime = ADC_SAMPLETIME_8CYCLES_5; } sConfig.SingleDiff = ADC_SINGLE_ENDED; sConfig.OffsetNumber = ADC_OFFSET_NONE; sConfig.OffsetRightShift = DISABLE; sConfig.OffsetSignedSaturation = DISABLE; #elif defined(STM32L4) if (channel == ADC_CHANNEL_VREFINT || channel == ADC_CHANNEL_TEMPSENSOR || channel == ADC_CHANNEL_VBAT) { sConfig.SamplingTime = ADC_SAMPLETIME_247CYCLES_5; } else { sConfig.SamplingTime = ADC_SAMPLETIME_12CYCLES_5; } sConfig.SingleDiff = ADC_SINGLE_ENDED; sConfig.OffsetNumber = ADC_OFFSET_NONE; sConfig.Offset = 0; #else #error Unsupported processor #endif #if defined(STM32F0) // On the STM32F0 we must select only one channel at a time to sample, so clear all // channels before calling HAL_ADC_ConfigChannel, which will select the desired one. adc_handle->Instance->CHSELR = 0; #endif HAL_ADC_ConfigChannel(adc_handle, &sConfig); }
void BSP_ADC_Init(void) { ADC_ChannelConfTypeDef ChannelConfStruct; GPIO_InitTypeDef GPIO_InitStruct; EXP_BOARD_POT_PIN_CLK_ENABLE() ; EXP_BOARD_POT_ADC_CLK_ENABLE() ; ADC_HandleStruct.Instance = ADC1; ADC_HandleStruct.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; ADC_HandleStruct.Init.Resolution = ADC_RESOLUTION_12B; ADC_HandleStruct.Init.DataAlign = ADC_DATAALIGN_RIGHT; ADC_HandleStruct.Init.ScanConvMode = DISABLE; ADC_HandleStruct.Init.EOCSelection = ADC_EOC_SINGLE_CONV; ADC_HandleStruct.Init.ContinuousConvMode = ENABLE; ADC_HandleStruct.Init.NbrOfConversion = 1; ADC_HandleStruct.Init.DiscontinuousConvMode = DISABLE; ADC_HandleStruct.Init.ExternalTrigConv = ADC_SOFTWARE_START; ADC_HandleStruct.Init.DMAContinuousRequests = DISABLE; ADC_HandleStruct.Init.NbrOfDiscConversion = 0; ADC_HandleStruct.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; ADC_HandleStruct.Init.EOCSelection = DISABLE; GPIO_InitStruct.Pin = EXP_BOARD_POT_PIN; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FAST; HAL_GPIO_Init(EXP_BOARD_POT_PORT, &GPIO_InitStruct); ChannelConfStruct.Channel = EXP_BOARD_POT_CHANNEL; ChannelConfStruct.Offset = 0; ChannelConfStruct.Rank = 1; ChannelConfStruct.SamplingTime = ADC_SAMPLETIME_15CYCLES; HAL_ADC_Init(&ADC_HandleStruct); HAL_ADC_ConfigChannel(&ADC_HandleStruct, &ChannelConfStruct); HAL_ADC_Start(&ADC_HandleStruct); }
/*---------------------------------------------------------------------------- * Initialize the GPIO associated with the LED *---------------------------------------------------------------------------*/ void initialize_Temp (void) { ADCInit.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; ADCInit.ContinuousConvMode = DISABLE; ADCInit.DataAlign = ADC_DATAALIGN_RIGHT; ADCInit.DiscontinuousConvMode = DISABLE; ADCInit.DMAContinuousRequests = DISABLE; ADCInit.EOCSelection = ADC_EOC_SINGLE_CONV; ADCInit.ExternalTrigConv = ADC_SOFTWARE_START; ADCInit.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; ADCInit.NbrOfConversion= 1; ADCInit.NbrOfDiscConversion = 0; ADCInit.Resolution = ADC_RESOLUTION_12B; ADCInit.ScanConvMode = DISABLE; ADCHandleinit.ErrorCode = HAL_ADC_ERROR_NONE; ADCHandleinit.Init.ClockPrescaler = ADCInit.ClockPrescaler; ADCHandleinit.Init.ContinuousConvMode = ADCInit.ContinuousConvMode; ADCHandleinit.Init.DataAlign = ADCInit.DataAlign; ADCHandleinit.Init.DiscontinuousConvMode = ADCInit.DiscontinuousConvMode; ADCHandleinit.Init.DMAContinuousRequests = ADCInit.DMAContinuousRequests; ADCHandleinit.Init.EOCSelection = ADCInit.EOCSelection; ADCHandleinit.Init.ExternalTrigConv = ADCInit.ExternalTrigConv; ADCHandleinit.Init.ExternalTrigConvEdge = ADCInit.ExternalTrigConvEdge; ADCHandleinit.Init.NbrOfConversion = ADCInit.NbrOfConversion; ADCHandleinit.Init.NbrOfDiscConversion = ADCInit.NbrOfDiscConversion; ADCHandleinit.Init.Resolution = ADCInit.Resolution; ADCHandleinit.Init.ScanConvMode = ADCInit.ScanConvMode; ADCHandleinit.Instance = ADC1; ADCHandleinit.Lock = HAL_UNLOCKED; ADCHandleinit.NbrOfCurrentConversionRank = 1; HAL_ADC_Init(&ADCHandleinit); __HAL_RCC_ADC1_CLK_ENABLE(); channelConfig.Channel = ADC_CHANNEL_16; channelConfig.Offset = 0; channelConfig.Rank = 1; channelConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES; HAL_ADC_ConfigChannel(&ADCHandleinit, &channelConfig); }
void adc_init_single(pyb_obj_adc_t *adc_obj) { if (!IS_ADC_CHANNEL(adc_obj->channel)) { return; } if (adc_obj->channel < ADC_NUM_GPIO_CHANNELS) { // Channels 0-16 correspond to real pins. Configure the GPIO pin in // ADC mode. const pin_obj_t *pin = pin_adc1[adc_obj->channel]; GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.Pin = pin->pin_mask; GPIO_InitStructure.Mode = GPIO_MODE_ANALOG; GPIO_InitStructure.Pull = GPIO_NOPULL; HAL_GPIO_Init(pin->gpio, &GPIO_InitStructure); } ADCx_CLK_ENABLE(); ADC_HandleTypeDef *adcHandle = &adc_obj->handle; adcHandle->Instance = ADCx; adcHandle->Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2; adcHandle->Init.Resolution = ADC_RESOLUTION12b; adcHandle->Init.ScanConvMode = DISABLE; adcHandle->Init.ContinuousConvMode = DISABLE; adcHandle->Init.DiscontinuousConvMode = DISABLE; adcHandle->Init.NbrOfDiscConversion = 0; adcHandle->Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; adcHandle->Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1; adcHandle->Init.DataAlign = ADC_DATAALIGN_RIGHT; adcHandle->Init.NbrOfConversion = 1; adcHandle->Init.DMAContinuousRequests = DISABLE; adcHandle->Init.EOCSelection = DISABLE; HAL_ADC_Init(adcHandle); ADC_ChannelConfTypeDef sConfig; sConfig.Channel = adc_obj->channel; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES; sConfig.Offset = 0; HAL_ADC_ConfigChannel(adcHandle, &sConfig); }
void adc_init() { HAL_Status status = HAL_ERROR; ADC_InitParam initParam; initParam.delay = ADC_FIRST_DELAY; initParam.freq = ADC_FEQ; #ifdef ADC_TEST_FIFO initParam.mode = ADC_BURST_CONV; #else initParam.mode = ADC_CONTI_CONV; #endif status = HAL_ADC_Init(&initParam); if (status != HAL_OK) { printf("ADC init error %d\n", status); return; } #ifdef ADC_IT_MODE #ifdef ADC_TEST_FIFO status = HAL_ADC_FifoConfigChannel(ADC_INCH, ADC_SELECT_ENABLE); #else status = HAL_ADC_ConfigChannel(ADC_INCH, ADC_SELECT_ENABLE, ADC_IRQ_MODE, 0, 0); #endif if (status != HAL_OK) { printf("ADC config error %d\n", status); return; } status = HAL_ADC_EnableIRQCallback(ADC_INCH, adc_callback, NULL); if (status != HAL_OK) { printf("ADC IRQ Enable error %d\n", status); return; } status = HAL_ADC_Start_Conv_IT(); if (status != HAL_OK) { printf("ADC it mode start error %d\n", status); return; } #endif }
/** * @brief ADC configuration * @param None * @retval None */ static void ADC_Config(void) { ADC_ChannelConfTypeDef sConfig; /* ADC Initialization */ AdcHandle.Instance = ADCx; AdcHandle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; AdcHandle.Init.Resolution = ADC_RESOLUTION12b; AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; AdcHandle.Init.ScanConvMode = DISABLE; /* Sequencer disabled (ADC conversion on only 1 channel: channel set on rank 1) */ AdcHandle.Init.EOCSelection = EOC_SINGLE_CONV; AdcHandle.Init.LowPowerAutoWait = DISABLE; AdcHandle.Init.ContinuousConvMode = DISABLE; /* Continuous mode disabled to have only 1 conversion at each conversion trig */ AdcHandle.Init.NbrOfConversion = 1; /* Parameter discarded because sequencer is disabled */ AdcHandle.Init.DiscontinuousConvMode = DISABLE; /* Parameter discarded because sequencer is disabled */ AdcHandle.Init.NbrOfDiscConversion = 1; /* Parameter discarded because sequencer is disabled */ AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T2_TRGO; /* Conversion start trigged at each external event */ AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING; AdcHandle.Init.DMAContinuousRequests = ENABLE; AdcHandle.Init.Overrun = OVR_DATA_OVERWRITTEN; if (HAL_ADC_Init(&AdcHandle) != HAL_OK) { /* ADC initialization Error */ Error_Handler(); } /* Configure ADC regular channel */ sConfig.Channel = ADCx_CHANNEL; sConfig.Rank = ADC_REGULAR_RANK_1; sConfig.SamplingTime = ADC_SAMPLETIME_19CYCLES_5; sConfig.SingleDiff = ADC_SINGLE_ENDED; sConfig.OffsetNumber = ADC_OFFSET_NONE; sConfig.Offset = 0; if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK) { /* Channel Configuration Error */ Error_Handler(); } }
/** * Configure an ADC channel on the STM32F4 ADC. * * @param dev The ADC device to configure * @param cnum The channel on the ADC device to configure * @param cfgdata An opaque pointer to channel config, expected to be * a ADC_ChannelConfTypeDef * * @return 0 on success, non-zero on failure. */ static int stm32f4_adc_configure_channel(struct adc_dev *dev, uint8_t cnum, void *cfgdata) { int rc; ADC_HandleTypeDef *hadc; struct stm32f4_adc_dev_cfg *cfg; struct adc_chan_config *chan_cfg; GPIO_InitTypeDef gpio_td; rc = OS_EINVAL; if (dev == NULL && !IS_ADC_CHANNEL(cnum)) { goto err; } cfg = (struct stm32f4_adc_dev_cfg *)dev->ad_dev.od_init_arg; hadc = cfg->sac_adc_handle; chan_cfg = &((struct adc_chan_config *)cfg->sac_chans)[cnum]; cfgdata = (ADC_ChannelConfTypeDef *)cfgdata; if ((HAL_ADC_ConfigChannel(hadc, cfgdata)) != HAL_OK) { goto err; } dev->ad_chans[cnum].c_res = chan_cfg->c_res; dev->ad_chans[cnum].c_refmv = chan_cfg->c_refmv; dev->ad_chans[cnum].c_configured = 1; dev->ad_chans[cnum].c_cnum = cnum; if (stm32f4_resolve_adc_gpio(hadc, cnum, &gpio_td)) { goto err; } hal_gpio_init_stm(gpio_td.Pin, &gpio_td); return (OS_OK); err: return (rc); }
void CAM_ADC_init(void) { /* * Enable ADC clock */ __ADC1_CLK_ENABLE(); /* Variables */ ADC_ChannelConfTypeDef sADCConfig; /* * ADC Initialization */ AdcHandle.Instance = ADC1; AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2; AdcHandle.Init.Resolution = ADC_RESOLUTION8b; AdcHandle.Init.ScanConvMode = ENABLE; AdcHandle.Init.ContinuousConvMode = ENABLE; AdcHandle.Init.DiscontinuousConvMode = DISABLE; AdcHandle.Init.NbrOfDiscConversion = 0; AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING; AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T2_TRGO; AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; AdcHandle.Init.NbrOfConversion = 1; AdcHandle.Init.DMAContinuousRequests = ENABLE; AdcHandle.Init.EOCSelection = ENABLE; HAL_ADC_Init(&AdcHandle); /* * Configure channel 0 */ sADCConfig.Channel = ADC_CHANNEL_0; sADCConfig.Rank = 1; sADCConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; sADCConfig.Offset = 0; HAL_ADC_ConfigChannel(&AdcHandle, &sADCConfig); }
/** * @brief ADC1 Initialization Function * @param None * @retval None */ static void MX_ADC1_Init(void) { /* USER CODE BEGIN ADC1_Init 0 */ /* USER CODE END ADC1_Init 0 */ ADC_ChannelConfTypeDef sConfig = {0}; /* USER CODE BEGIN ADC1_Init 1 */ /* USER CODE END ADC1_Init 1 */ /** Common config */ hadc1.Instance = ADC1; hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE; hadc1.Init.ContinuousConvMode = DISABLE; hadc1.Init.DiscontinuousConvMode = DISABLE; hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START; hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc1.Init.NbrOfConversion = 1; if (HAL_ADC_Init(&hadc1) != HAL_OK) { Error_Handler(); } /** Configure Regular Channel */ sConfig.Channel = ADC_CHANNEL_1; sConfig.Rank = ADC_REGULAR_RANK_1; sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN ADC1_Init 2 */ /* USER CODE END ADC1_Init 2 */ }