void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { GPIO_InitTypeDef GPIO_InitStruct; if(hadc->Instance==ADC1) { /* Peripheral clock enable */ __ADC1_CLK_ENABLE(); /**ADC GPIO Configuration PA0 ------> ADC_IN0 PA1 ------> ADC_IN1 PA4 ------> ADC_IN4 PA5 ------> ADC_IN5 PA6 ------> ADC_IN6 PB1 ------> ADC_IN9 */ GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_4|GPIO_PIN_5 |GPIO_PIN_6; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_1; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); } }
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { GPIO_InitTypeDef GPIO_InitStruct; if(hadc->Instance==ADC1) { /* USER CODE BEGIN ADC1_MspInit 0 */ /* USER CODE END ADC1_MspInit 0 */ /* Peripheral clock enable */ __ADC1_CLK_ENABLE(); /**ADC1 GPIO Configuration PA1 ------> ADC1_IN1 */ GPIO_InitStruct.Pin = GPIO_PIN_1; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* Peripheral interrupt init*/ HAL_NVIC_SetPriority(ADC_IRQn, 0, 0); HAL_NVIC_EnableIRQ(ADC_IRQn); /* USER CODE BEGIN ADC1_MspInit 1 */ /* USER CODE END ADC1_MspInit 1 */ } }
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { GPIO_InitTypeDef GPIO_InitStruct; if(hadc->Instance==ADC1) { /* USER CODE BEGIN ADC1_MspInit 0 */ /* USER CODE END ADC1_MspInit 0 */ /* Peripheral clock enable */ __ADC1_CLK_ENABLE(); /**ADC1 GPIO Configuration PA1 ------> ADC1_IN1 */ GPIO_InitStruct.Pin = GPIO_PIN_1; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* USER CODE BEGIN ADC1_MspInit 1 */ /* USER CODE END ADC1_MspInit 1 */ } }
void analogin_init(analogin_t *obj, PinName pin) { // Get the peripheral name (ADC_1, ADC_2...) from the pin and assign it to the object obj->adc = (ADCName)pinmap_peripheral(pin, PinMap_ADC); MBED_ASSERT(obj->adc != (ADCName)NC); // Configure GPIO pinmap_pinout(pin, PinMap_ADC); // Save pin number for the read function obj->pin = pin; // The ADC initialization is done once if (adc_inited == 0) { adc_inited = 1; // Enable ADC clock __ADC1_CLK_ENABLE(); // Configure ADC AdcHandle.Instance = (ADC_TypeDef *)(obj->adc); 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 Configuration * @brief Configures ADC1 Channel 16 so that temperature values can be read */ void ADC_config(void) { // TODO: Make this configuration proper so that it actually works ADC_ChannelConfTypeDef ADC1_ch16; // Initialize values for ADC1 handle type def ADC1_Handle.Instance = ADC1; ADC1_Handle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4; ADC1_Handle.Init.Resolution = ADC_RESOLUTION_12B; ADC1_Handle.Init.DataAlign = ADC_DATAALIGN_RIGHT; ADC1_Handle.Init.ScanConvMode = DISABLE; ADC1_Handle.Init.EOCSelection = DISABLE; ADC1_Handle.Init.ContinuousConvMode = ENABLE; // ADC1_Handle.Init.DMAContinuousRequests = DISABLE; ADC1_Handle.Init.NbrOfConversion = 1; ADC1_Handle.Init.DiscontinuousConvMode = DISABLE; ADC1_Handle.Init.NbrOfDiscConversion = 0; ADC1_Handle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1; // ADC1_Handle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; // // Initialize values for temperature sensor (Temperature analog channel is Ch16 of ADC1) ADC1_ch16.Channel = ADC_CHANNEL_16; ADC1_ch16.Rank = 1; ADC1_ch16.SamplingTime = ADC_SAMPLETIME_480CYCLES; ADC1_ch16.Offset = 0; // Enable ADC clock __ADC1_CLK_ENABLE(); // Initialize clock with error handling if(HAL_ADC_Init(&ADC1_Handle)!=HAL_OK){ //Error_Handler(ADC_INIT_FAIL); printf("adc init fail\n"); } // Configure temperature sensor peripheral HAL_ADC_ConfigChannel(&ADC1_Handle, &ADC1_ch16); HAL_ADC_Start(&ADC1_Handle); // Allot values to the kalman filtration struct for the temperature sensor kalman_temperature.q = 0.3; kalman_temperature.r = 1.2; kalman_temperature.x = 1000.0; kalman_temperature.p = 0.0; kalman_temperature.k = 0.0; // Initialize temperature sensor mutex temperatureMutex = osMutexCreate(temperatureMutexPtr); }
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); }
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { if(hadc->Instance==ADC1) { /* USER CODE BEGIN ADC1_MspInit 0 */ /* USER CODE END ADC1_MspInit 0 */ /* Peripheral clock enable */ __ADC1_CLK_ENABLE(); /* USER CODE BEGIN ADC1_MspInit 1 */ /* USER CODE END ADC1_MspInit 1 */ } }
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { GPIO_InitTypeDef GPIO_InitStruct; if(hadc->Instance==ADC1) { /* USER CODE BEGIN ADC1_MspInit 0 */ /* USER CODE END ADC1_MspInit 0 */ /* Peripheral clock enable */ __ADC1_CLK_ENABLE(); /**ADC1 GPIO Configuration PA3 ------> ADC1_IN3 PA4 ------> ADC1_IN4 PA5 ------> ADC1_IN5 PA6 ------> ADC1_IN6 PA7 ------> ADC1_IN7 */ GPIO_InitStruct.Pin = Linia1_Pin|Linia2_Pin|Sharp2_Pin|Sharp1_Pin |V_Control_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* Peripheral DMA init*/ hdma_adc1.Instance = DMA1_Channel1; hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE; hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_adc1.Init.Mode = DMA_CIRCULAR; hdma_adc1.Init.Priority = DMA_PRIORITY_LOW; HAL_DMA_Init(&hdma_adc1); __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1); /* Peripheral interrupt init*/ HAL_NVIC_SetPriority(ADC1_2_IRQn, 0, 0); HAL_NVIC_EnableIRQ(ADC1_2_IRQn); /* USER CODE BEGIN ADC1_MspInit 1 */ /* USER CODE END ADC1_MspInit 1 */ } }
/** * @brief ADC MSP Init * @param hadc : ADC handle * @retval None */ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) { GPIO_InitTypeDef GPIO_InitStruct; /*##-1- Enable peripherals and GPIO Clocks #################################*/ /* Enable GPIO clock ****************************************/ __GPIOA_CLK_ENABLE(); /* ADC1 Periph clock enable */ __ADC1_CLK_ENABLE(); /*##-2- Configure peripheral GPIO ##########################################*/ /* ADC3 Channel8 GPIO pin configuration */ GPIO_InitStruct.Pin = GPIO_PIN_0; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); }
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { GPIO_InitTypeDef GPIO_InitStruct; if(hadc->Instance==ADC1) { /* USER CODE BEGIN ADC1_MspInit 0 */ /* USER CODE END ADC1_MspInit 0 */ /* Peripheral clock enable */ __ADC1_CLK_ENABLE(); /**ADC1 GPIO Configuration PC0 ------> ADC1_IN10 PC1 ------> ADC1_IN11 PC2 ------> ADC1_IN12 PC3 ------> ADC1_IN13 */ GPIO_InitStruct.Pin = Ain1_Pin|Ain2_Pin|Ain3_Pin|Ain4_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /* Peripheral DMA init*/ hdma_adc1.Instance = DMA2_Stream0; hdma_adc1.Init.Channel = DMA_CHANNEL_0; hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE; hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_adc1.Init.Mode = DMA_CIRCULAR; hdma_adc1.Init.Priority = DMA_PRIORITY_MEDIUM; hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_DISABLE; hdma_adc1.Init.MemBurst = DMA_MBURST_SINGLE; HAL_DMA_Init(&hdma_adc1); __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1); /* USER CODE BEGIN ADC1_MspInit 1 */ /* USER CODE END ADC1_MspInit 1 */ } }
void APP_ADC_Init(ADC_HandleTypeDef *hadc) { GPIO_InitTypeDef GPIO_InitStruct; static DMA_HandleTypeDef DmaHandle; /*##-1- Enable peripherals and GPIO Clocks #################################*/ /* Enable GPIO clock ****************************************/ __GPIOA_CLK_ENABLE(); /* ADC1 Periph clock enable */ __ADC1_CLK_ENABLE(); /* Enable DMA1 clock */ __DMA1_CLK_ENABLE(); /*##- 2- Configure peripheral GPIO #########################################*/ /* ADC3 Channel8 GPIO pin configuration */ GPIO_InitStruct.Pin = GPIO_PIN_0| GPIO_PIN_1; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /*##- 3- Configure DMA #####################################################*/ /*********************** Configure DMA parameters ***************************/ DmaHandle.Instance = DMA1_Channel1; DmaHandle.Init.Direction = DMA_PERIPH_TO_MEMORY; DmaHandle.Init.PeriphInc = DMA_PINC_DISABLE; DmaHandle.Init.MemInc = DMA_MINC_ENABLE; DmaHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; DmaHandle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; DmaHandle.Init.Mode = DMA_CIRCULAR; DmaHandle.Init.Priority = DMA_PRIORITY_MEDIUM; DmaHandle.Init.Request = DMA_REQUEST_0; /* Deinitialize & Initialize the DMA for new transfer */ HAL_DMA_DeInit(&DmaHandle); HAL_DMA_Init(&DmaHandle); /* Associate the DMA handle */ __HAL_LINKDMA(hadc, DMA_Handle, DmaHandle); /* NVIC configuration for DMA Input data interrupt */ HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 1, 0); HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); }
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { GPIO_InitTypeDef GPIO_InitStruct; if(hadc->Instance==ADC1) { /* USER CODE BEGIN ADC1_MspInit 0 */ /* USER CODE END ADC1_MspInit 0 */ /* Peripheral clock enable */ __ADC1_CLK_ENABLE(); /**ADC1 GPIO Configuration PA0-WKUP ------> ADC1_IN0 PA1 ------> ADC1_IN1 */ GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* Peripheral DMA init*/ hdma_adc1.Instance = DMA2_Stream0; hdma_adc1.Init.Channel = DMA_CHANNEL_0; hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE; hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; hdma_adc1.Init.Mode = DMA_CIRCULAR; hdma_adc1.Init.Priority = DMA_PRIORITY_LOW; hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_DISABLE; HAL_DMA_Init(&hdma_adc1); __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1); /* Peripheral interrupt init*/ HAL_NVIC_SetPriority(ADC_IRQn, 0, 0); HAL_NVIC_EnableIRQ(ADC_IRQn); /* USER CODE BEGIN ADC1_MspInit 1 */ /* USER CODE END ADC1_MspInit 1 */ } }
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { GPIO_InitTypeDef GPIO_InitStruct; if(hadc->Instance==ADC1) { /* Peripheral clock enable */ __ADC1_CLK_ENABLE(); /**ADC GPIO Configuration PB0 ------> ADC_IN8 */ GPIO_InitStruct.Pin = GPIO_PIN_0; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); } }
void ClockEnable (void) { __GPIOA_CLK_ENABLE(); __GPIOB_CLK_ENABLE(); __GPIOC_CLK_ENABLE(); __GPIOD_CLK_ENABLE(); __GPIOE_CLK_ENABLE(); __GPIOF_CLK_ENABLE(); __GPIOG_CLK_ENABLE(); __GPIOH_CLK_ENABLE(); __ADC1_CLK_ENABLE(); __ADC2_CLK_ENABLE(); __DAC_CLK_ENABLE(); __FSMC_CLK_ENABLE(); __SPI2_CLK_ENABLE(); __DMA2_CLK_ENABLE(); __TIM1_CLK_ENABLE(); __TIM2_CLK_ENABLE(); }
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { GPIO_InitTypeDef GPIO_InitStruct; if(hadc->Instance==ADC1) { /* USER CODE BEGIN ADC1_MspInit 0 */ /* USER CODE END ADC1_MspInit 0 */ /* Peripheral clock enable */ __ADC1_CLK_ENABLE(); /**ADC GPIO Configuration PA0 ------> ADC_IN0 PA1 ------> ADC_IN1 */ GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* Peripheral DMA init*/ hdma_adc.Instance = DMA1_Channel1; hdma_adc.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_adc.Init.PeriphInc = DMA_PINC_DISABLE; hdma_adc.Init.MemInc = DMA_MINC_ENABLE; hdma_adc.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_adc.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_adc.Init.Mode = DMA_CIRCULAR; hdma_adc.Init.Priority = DMA_PRIORITY_LOW; HAL_DMA_Init(&hdma_adc); __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc); /* USER CODE BEGIN ADC1_MspInit 1 */ /* USER CODE END ADC1_MspInit 1 */ } }
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); }
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { GPIO_InitTypeDef GPIO_InitStruct; if(hadc->Instance==ADC1) { /* USER CODE BEGIN ADC1_MspInit 0 */ /* USER CODE END ADC1_MspInit 0 */ /* Peripheral clock enable */ __ADC1_CLK_ENABLE(); /**ADC GPIO Configuration PC0 ------> ADC_IN10 PC1 ------> ADC_IN11 PA4 ------> ADC_IN4 PB0 ------> ADC_IN8 */ GPIO_InitStruct.Pin = ADC_4i_Pin|ADC_4v_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); GPIO_InitStruct.Pin = ADC_3v_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(ADC_3v_GPIO_Port, &GPIO_InitStruct); GPIO_InitStruct.Pin = ADC_3i_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(ADC_3i_GPIO_Port, &GPIO_InitStruct); /* USER CODE BEGIN ADC1_MspInit 1 */ /* USER CODE END ADC1_MspInit 1 */ } }
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { GPIO_InitTypeDef GPIO_InitStruct; if(hadc->Instance==ADC1) { /* USER CODE BEGIN ADC1_MspInit 0 */ /* USER CODE END ADC1_MspInit 0 */ /* Peripheral clock enable */ __ADC1_CLK_ENABLE(); /**ADC GPIO Configuration PA0 ------> ADC_IN0 PA1 ------> ADC_IN1 PA2 ------> ADC_IN2 PA3 ------> ADC_IN3 PA4 ------> ADC_IN4 PA5 ------> ADC_IN5 PA6 ------> ADC_IN6 PA7 ------> ADC_IN7 PB0 ------> ADC_IN8 */ 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); GPIO_InitStruct.Pin = GPIO_PIN_0; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* USER CODE BEGIN ADC1_MspInit 1 */ /* USER CODE END ADC1_MspInit 1 */ } }
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { GPIO_InitTypeDef GPIO_InitStruct; if(hadc->Instance==ADC1) { /* USER CODE BEGIN ADC1_MspInit 0 */ /* USER CODE END ADC1_MspInit 0 */ /* Peripheral clock enable */ __ADC1_CLK_ENABLE(); /**ADC1 GPIO Configuration PB0 ------> ADC1_IN8 PB1 ------> ADC1_IN9 */ GPIO_InitStruct.Pin = keyboard_l_Pin|keyboard_r_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* Peripheral DMA init*/ hdma_adc1.Instance = DMA1_Channel1; hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE; hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_adc1.Init.Mode = DMA_NORMAL; hdma_adc1.Init.Priority = DMA_PRIORITY_LOW; HAL_DMA_Init(&hdma_adc1); __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1); /* USER CODE BEGIN ADC1_MspInit 1 */ /* USER CODE END ADC1_MspInit 1 */ } }
/** * Configure adc and temp channel */ void ConfigureADC(void) { ADC_ChannelConfTypeDef adcChannel; __ADC1_CLK_ENABLE(); // HAL_NVIC_SetPriority(ADC_IRQn, 0, 0); // HAL_NVIC_EnableIRQ(ADC_IRQn); g_AdcHandle.Instance = ADC1; // g_AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2; g_AdcHandle.Init.Resolution = ADC_RESOLUTION_12B; g_AdcHandle.Init.ScanConvMode = DISABLE; g_AdcHandle.Init.ContinuousConvMode = ENABLE; // g_AdcHandle.Init.DiscontinuousConvMode = DISABLE; // g_AdcHandle.Init.NbrOfDiscConversion = 0; g_AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; g_AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1; g_AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; g_AdcHandle.Init.NbrOfConversion = 1; // g_AdcHandle.Init.DMAContinuousRequests = ENABLE; // g_AdcHandle.Init.EOCSelection = DISABLE; HAL_ADC_Init(&g_AdcHandle); adcChannel.Channel = ADC_CHANNEL_TEMPSENSOR; adcChannel.Rank = 1; adcChannel.SamplingTime = ADC_SAMPLETIME_144CYCLES; adcChannel.Offset = 0; HAL_ADC_ConfigChannel(&g_AdcHandle, &adcChannel); HAL_ADC_Start(&g_AdcHandle); }
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { GPIO_InitTypeDef GPIO_InitStruct; if(hadc->Instance==ADC1) { /* Peripheral clock enable */ __ADC1_CLK_ENABLE(); /**ADC1 GPIO Configuration PA0-WKUP ------> ADC1_IN0 PA1 ------> ADC1_IN1 PA2 ------> ADC1_IN2 PA3 ------> ADC1_IN3 PA4 ------> ADC1_IN4 */ GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 |GPIO_PIN_4; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); } }
void initAdc() { uhADCxConvertedValue1 = 0; uhADCxConvertedValue2 = 0; adcConfigured = 0; sampleIndex = 100; //probably makes more sense for this to be in main for sampleRun = 0; wrongThings = 0; __ADC1_CLK_ENABLE(); __ADC2_CLK_ENABLE(); __ADC3_CLK_ENABLE(); __GPIOA_CLK_ENABLE(); __GPIOB_CLK_ENABLE(); __GPIOC_CLK_ENABLE(); __ADC_FORCE_RESET(); __ADC_RELEASE_RESET(); AdcHandle1.Instance = ADC1; AdcHandle1.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2; AdcHandle1.Init.Resolution = ADC_RESOLUTION12b; AdcHandle1.Init.ScanConvMode = DISABLE; AdcHandle1.Init.ContinuousConvMode = ENABLE; AdcHandle1.Init.DiscontinuousConvMode = DISABLE; AdcHandle1.Init.NbrOfDiscConversion = 0; AdcHandle1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; AdcHandle1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1; AdcHandle1.Init.DataAlign = ADC_DATAALIGN_RIGHT; AdcHandle1.Init.NbrOfConversion = 1; AdcHandle1.Init.DMAContinuousRequests = DISABLE; AdcHandle1.Init.EOCSelection = DISABLE; if(HAL_ADC_Init(&AdcHandle1) != HAL_OK) { /* Initiliazation Error */ //Error_Handler(); wrongThings++; } AdcHandle2.Instance = ADC2; AdcHandle2.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2; AdcHandle2.Init.Resolution = ADC_RESOLUTION12b; AdcHandle2.Init.ScanConvMode = DISABLE; AdcHandle2.Init.ContinuousConvMode = ENABLE; AdcHandle2.Init.DiscontinuousConvMode = DISABLE; AdcHandle2.Init.NbrOfDiscConversion = 0; AdcHandle2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; AdcHandle2.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1; AdcHandle2.Init.DataAlign = ADC_DATAALIGN_RIGHT; AdcHandle2.Init.NbrOfConversion = 1; AdcHandle2.Init.DMAContinuousRequests = DISABLE; AdcHandle2.Init.EOCSelection = DISABLE; if(HAL_ADC_Init(&AdcHandle2) != HAL_OK) { /* Initiliazation Error */ //Error_Handler(); wrongThings++; } AdcHandle3.Instance = ADC3; AdcHandle3.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2; AdcHandle3.Init.Resolution = ADC_RESOLUTION12b; AdcHandle3.Init.ScanConvMode = DISABLE; AdcHandle3.Init.ContinuousConvMode = ENABLE; AdcHandle3.Init.DiscontinuousConvMode = DISABLE; AdcHandle3.Init.NbrOfDiscConversion = 0; AdcHandle3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; AdcHandle3.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1; AdcHandle3.Init.DataAlign = ADC_DATAALIGN_RIGHT; AdcHandle3.Init.NbrOfConversion = 1; AdcHandle3.Init.DMAContinuousRequests = DISABLE; AdcHandle3.Init.EOCSelection = DISABLE; if(HAL_ADC_Init(&AdcHandle3) != HAL_OK) { /* Initiliazation Error */ //Error_Handler(); wrongThings++; } sConfig1.Channel = ADC_MIC_CHANNEL; sConfig1.Rank = 1; sConfig1.SamplingTime = ADC_SAMPLETIME_3CYCLES; sConfig1.Offset = 0; sConfig2.Channel = ADC_RX_I_CHANNEL; sConfig2.Rank = 1; sConfig2.SamplingTime = ADC_SAMPLETIME_3CYCLES; sConfig2.Offset = 0; sConfig3.Channel = ADC_RX_Q_CHANNEL; sConfig3.Rank = 1; sConfig3.SamplingTime = ADC_SAMPLETIME_3CYCLES; sConfig3.Offset = 0; if(HAL_ADC_ConfigChannel(&AdcHandle1, &sConfig1) != HAL_OK) { /* Channel Configuration Error */ //Error_Handler(); wrongThings++; } if(HAL_ADC_ConfigChannel(&AdcHandle2, &sConfig2) != HAL_OK) { /* Channel Configuration Error */ //Error_Handler(); wrongThings++; } if(HAL_ADC_ConfigChannel(&AdcHandle3, &sConfig3) != HAL_OK) { /* Channel Configuration Error */ //Error_Handler(); wrongThings++; } }
/** \brief Init ADC device. * * \param dev_num bsp_dev_adc_t: ADC dev num. * \param mode_conf mode_config_proto_t*: Mode config proto. * \return bsp_status_t: status of the init. * */ bsp_status_t bsp_adc_init(bsp_dev_adc_t dev_num) { uint32_t adc_chan_num; ADC_HandleTypeDef* hadc; ADC_ChannelConfTypeDef* hadc_chan; bsp_adc_deinit(dev_num); /* Init the ADC GPIO */ adc_gpio_hw_init(dev_num); /* Configure the ADC peripheral */ __ADC1_CLK_ENABLE(); hadc = &adc_handle[dev_num]; hadc->Instance = BSP_ADC1; /* Max ADCCLK 36MHz PCLK2=84MHz so divide it by 4 => ADCCLK = 21MHz */ hadc->Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV4; hadc->Init.Resolution = ADC_RESOLUTION12b; hadc->Init.ScanConvMode = DISABLE; hadc->Init.ContinuousConvMode = DISABLE; hadc->Init.DiscontinuousConvMode = DISABLE; hadc->Init.NbrOfDiscConversion = 0; hadc->Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc->Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1; hadc->Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc->Init.NbrOfConversion = 1; hadc->Init.DMAContinuousRequests = DISABLE; hadc->Init.EOCSelection = EOC_SEQ_CONV; if(HAL_ADC_Init(hadc) != HAL_OK) { return BSP_ERROR; } /* Configure ADC regular channel */ switch(dev_num) { case BSP_DEV_ADC1: adc_chan_num = ADC_CHANNEL_1; break; case BSP_DEV_ADC_TEMPSENSOR : adc_chan_num = ADC_CHANNEL_TEMPSENSOR; break; case BSP_DEV_ADC_VREFINT: adc_chan_num = ADC_CHANNEL_VREFINT; break; case BSP_DEV_ADC_VBAT: adc_chan_num = ADC_CHANNEL_VBAT; break; default: adc_chan_num = ADC_CHANNEL_TEMPSENSOR; break; } hadc_chan = &adc_chan_conf[dev_num]; hadc_chan->Channel = adc_chan_num; hadc_chan->Rank = 1; hadc_chan->SamplingTime = ADC_SAMPLETIME_3CYCLES; hadc_chan->Offset = 0; /* Conversion is finished in 12 bits: 3 + 12 = 15 ADCCLK cycles 21MHz/15 = 1.4MHz = 0.71us */ hadc = &adc_handle[dev_num]; if(HAL_ADC_ConfigChannel(hadc, hadc_chan) != HAL_OK) { /* Channel Configuration Error */ return BSP_ERROR; } return BSP_OK; }
/* Hal MSP_Init */ void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { __ADC1_CLK_ENABLE(); }
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { GPIO_InitTypeDef GPIO_InitStruct; if(hadc->Instance==ADC1) { /* USER CODE BEGIN ADC1_MspInit 0 */ /* USER CODE END ADC1_MspInit 0 */ /* Peripheral clock enable */ __ADC1_CLK_ENABLE(); /**ADC1 GPIO Configuration PC4 ------> ADC1_IN14 PC5 ------> ADC1_IN15 */ GPIO_InitStruct.Pin = GPIO_PIN_4|GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /* Peripheral DMA init*/ hdma_adc1.Instance = DMA2_Stream0; hdma_adc1.Init.Channel = DMA_CHANNEL_0; hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE; hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_adc1.Init.Mode = DMA_CIRCULAR; hdma_adc1.Init.Priority = DMA_PRIORITY_HIGH; hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_DISABLE; HAL_DMA_Init(&hdma_adc1); __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1); /* USER CODE BEGIN ADC1_MspInit 1 */ /* USER CODE END ADC1_MspInit 1 */ } else if(hadc->Instance==ADC2) { /* USER CODE BEGIN ADC2_MspInit 0 */ /* USER CODE END ADC2_MspInit 0 */ /* Peripheral clock enable */ __ADC2_CLK_ENABLE(); /**ADC2 GPIO Configuration PB0 ------> ADC2_IN8 PB1 ------> ADC2_IN9 */ GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* USER CODE BEGIN ADC2_MspInit 1 */ /* USER CODE END ADC2_MspInit 1 */ } }
/* ADC init function */ void MX_ADC_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; /* Peripheral clock enable */ __ADC1_CLK_ENABLE(); /* DMA controller clock enable */ __DMA1_CLK_ENABLE(); /**ADC GPIO Configuration PA0-WKUP ------> ADC_IN0 */ GPIO_InitStruct.Pin = GPIO_PIN_0; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* Peripheral DMA init*/ DmaHandle.Instance = DMA1_Channel1; DmaHandle.Init.Request = DMA_REQUEST_0; DmaHandle.Init.Direction = DMA_PERIPH_TO_MEMORY; DmaHandle.Init.PeriphInc = DMA_PINC_DISABLE; DmaHandle.Init.MemInc = DMA_MINC_ENABLE; DmaHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; DmaHandle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; DmaHandle.Init.Mode = DMA_CIRCULAR; DmaHandle.Init.Priority = DMA_PRIORITY_MEDIUM; HAL_DMA_DeInit(&DmaHandle); HAL_DMA_Init(&DmaHandle); __HAL_LINKDMA(&AdcHandle, DMA_Handle, DmaHandle); /* DMA interrupt init */ HAL_NVIC_SetPriority(DMA1_Channel1_IRQn, 1, 0); HAL_NVIC_EnableIRQ(DMA1_Channel1_IRQn); ADC_ChannelConfTypeDef sConfig; ADC_AnalogWDGConfTypeDef AnalogWDGConfig; /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ AdcHandle.Instance = ADC1; AdcHandle.Init.OversamplingMode = DISABLE; AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV1; AdcHandle.Init.Resolution = ADC_RESOLUTION8b; AdcHandle.Init.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; AdcHandle.Init.ScanDirection = ADC_SCAN_DIRECTION_UPWARD; AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; AdcHandle.Init.ContinuousConvMode = ENABLE; AdcHandle.Init.DiscontinuousConvMode = DISABLE; AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIG_EDGE_NONE; AdcHandle.Init.DMAContinuousRequests = ENABLE; AdcHandle.Init.EOCSelection = EOC_SINGLE_CONV; AdcHandle.Init.Overrun = OVR_DATA_PRESERVED; AdcHandle.Init.LowPowerAutoWait = DISABLE; AdcHandle.Init.LowPowerFrequencyMode = DISABLE; AdcHandle.Init.LowPowerAutoOff = DISABLE; HAL_ADC_Init(&AdcHandle); HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED); sConfig.Channel = ADC_CHANNEL_0; HAL_ADC_ConfigChannel(&AdcHandle, &sConfig); /**Configure the analog watchdog */ AnalogWDGConfig.WatchdogMode = ADC_ANALOGWATCHDOG_SINGLE_REG; AnalogWDGConfig.Channel = ADC_CHANNEL_0; AnalogWDGConfig.ITMode = ENABLE; AnalogWDGConfig.HighThreshold = 0; AnalogWDGConfig.LowThreshold = 0; HAL_ADC_AnalogWDGConfig(&AdcHandle, &AnalogWDGConfig); HAL_ADC_Start_DMA(&AdcHandle, &resultDMA, DMA_BUFFER_SIZE); }
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { GPIO_InitTypeDef GPIO_InitStruct; if (hadc->Instance == ADC1) { /* USER CODE BEGIN ADC1_MspInit 0 */ /* USER CODE END ADC1_MspInit 0 */ /* Peripheral clock enable */ __ADC1_CLK_ENABLE() ; /**ADC1 GPIO Configuration PA7 ------> ADC1_IN7 PC4 ------> ADC1_IN14 PC5 ------> ADC1_IN15 */ GPIO_InitStruct.Pin = GYRO_TEMP_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GYRO_TEMP_GPIO_Port, &GPIO_InitStruct); GPIO_InitStruct.Pin = GYRO_RATE_Pin | VBAT_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /* Peripheral DMA init*/ hdma_adc1.Instance = DMA2_Stream0; hdma_adc1.Init.Channel = DMA_CHANNEL_0; hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE; hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_adc1.Init.Mode = DMA_CIRCULAR; hdma_adc1.Init.Priority = DMA_PRIORITY_LOW; hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_DISABLE; HAL_DMA_Init(&hdma_adc1); __HAL_LINKDMA(hadc, DMA_Handle, hdma_adc1); /* Peripheral interrupt init*/ HAL_NVIC_SetPriority(ADC_IRQn, 0, 4); HAL_NVIC_EnableIRQ(ADC_IRQn); /* USER CODE BEGIN ADC1_MspInit 1 */ /* USER CODE END ADC1_MspInit 1 */ } else if (hadc->Instance == ADC2) { /* USER CODE BEGIN ADC2_MspInit 0 */ /* USER CODE END ADC2_MspInit 0 */ /* Peripheral clock enable */ __ADC2_CLK_ENABLE() ; /**ADC2 GPIO Configuration PC0 ------> ADC2_IN10 PC1 ------> ADC2_IN11 PC3 ------> ADC2_IN13 PA4 ------> ADC2_IN4 PA5 ------> ADC2_IN5 PA6 ------> ADC2_IN6 */ GPIO_InitStruct.Pin = GPIO_PIN_0 | R_FRONT_RX_Pin | LINE_SENSOR_R1_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); GPIO_InitStruct.Pin = LINE_SENSOR_L1_Pin | L_DIAG_RX_Pin | L_FRONT_RX_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* Peripheral interrupt init*/ HAL_NVIC_SetPriority(ADC_IRQn, 0, 4); HAL_NVIC_EnableIRQ(ADC_IRQn); /* USER CODE BEGIN ADC2_MspInit 1 */ /* USER CODE END ADC2_MspInit 1 */ } else if (hadc->Instance == ADC3) { /* USER CODE BEGIN ADC3_MspInit 0 */ /* USER CODE END ADC3_MspInit 0 */ /* Peripheral clock enable */ __ADC3_CLK_ENABLE() ; /**ADC3 GPIO Configuration PC0 ------> ADC3_IN10 PC2 ------> ADC3_IN12 PA1 ------> ADC3_IN1 PA3 ------> ADC3_IN3 */ GPIO_InitStruct.Pin = GPIO_PIN_0 | LINE_SENSOR_R2_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); GPIO_InitStruct.Pin = LINE_SENSOR_F_Pin | LINE_SENSOR_L2_Pin; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* Peripheral interrupt init*/ HAL_NVIC_SetPriority(ADC_IRQn, 0, 4); HAL_NVIC_EnableIRQ(ADC_IRQn); /* USER CODE BEGIN ADC3_MspInit 1 */ /* USER CODE END ADC3_MspInit 1 */ } }