/** * @brief ADC MSP Initialization * This function configures the hardware resources used in this example: * - Peripheral's clock enable * - Peripheral's GPIO Configuration * @param hadc: ADC handle pointer * @retval None */ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) { GPIO_InitTypeDef GPIO_InitStruct; /*##-1- Enable peripherals and GPIO Clocks #################################*/ /* Enable GPIO clock */ ADCx_CHANNEL_GPIO_CLK_ENABLE(); /* ADC3 Periph clock enable */ ADCx_CLK_ENABLE(); /*##-2- Configure peripheral GPIO ##########################################*/ /* ADC Channel GPIO pin configuration */ GPIO_InitStruct.Pin = ADCx_CHANNEL_DIFF_HIGH; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(ADCx_CHANNEL_DIFF_HIGH_GPIO_PORT, &GPIO_InitStruct); GPIO_InitStruct.Pin = ADCx_CHANNEL_DIFF_LOW; HAL_GPIO_Init(ADCx_CHANNEL_DIFF_LOW_GPIO_PORT, &GPIO_InitStruct); /*##-3- Configure the NVIC #################################################*/ /* NVIC configuration for ADC interrupt */ /* Priority: high-priority */ HAL_NVIC_SetPriority(ADC1_2_IRQn, 0, 0); HAL_NVIC_EnableIRQ(ADC1_2_IRQn); }
adc::adc (void) { GPIO_InitTypeDef GPIO_InitStruct; /*##-1- Enable peripherals and GPIO Clocks #################################*/ /* ADC3 Periph clock enable */ ADCx_CLK_ENABLE() ; /* Enable GPIO clock ****************************************/ ADCx_CHANNEL_GPIO_CLK_ENABLE() ; /*##-2- Configure peripheral GPIO ##########################################*/ /* ADC3 Channel8 GPIO pin configuration */ GPIO_InitStruct.Pin = ADCx_CHANNEL_PIN; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init (ADCx_CHANNEL_GPIO_PORT, &GPIO_InitStruct); /*##-3- Configure the NVIC #################################################*/ /* NVIC configuration for DMA transfer complete interrupt (USART1_TX) */ HAL_NVIC_SetPriority (ADCx_IRQn, 15, 0); HAL_NVIC_EnableIRQ (ADCx_IRQn); ADC_ChannelConfTypeDef sConfig; /*##-1- Configure the ADC peripheral #######################################*/ AdcHandle.Instance = ADCx; AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV8; AdcHandle.Init.Resolution = ADC_RESOLUTION_12B; AdcHandle.Init.ScanConvMode = DISABLE; AdcHandle.Init.ContinuousConvMode = ENABLE; 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) asm("bkpt 0"); /*##-2- Configure ADC regular channel ######################################*/ sConfig.Channel = ADCx_CHANNEL; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; sConfig.Offset = 0; if (HAL_ADC_ConfigChannel (&AdcHandle, &sConfig) != HAL_OK) asm("bkpt 0"); /*##-3- Start the conversion process and enable interrupt ##################*/ if (HAL_ADC_Start_IT (&AdcHandle) != HAL_OK) asm("bkpt 0"); }
void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) { GPIO_InitTypeDef GPIO_InitStruct; static DMA_HandleTypeDef hdma_adc; /*##-1- Enable peripherals and GPIO Clocks #################################*/ /* ADC3 Periph clock enable */ ADCx_CLK_ENABLE(); /* Enable GPIO clock ****************************************/ ADCx_CHANNEL_GPIO_CLK_ENABLE(); /* Enable DMA2 clock */ DMAx_ADC_CLK_ENABLE(); /*##-2- Configure peripheral GPIO ##########################################*/ /* ADC Channel GPIO pin configuration */ GPIO_InitStruct.Pin = ADCx_CHANNEL_PIN_H; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(ADCx_CHANNEL_GPIO_PORT_H, &GPIO_InitStruct); GPIO_InitStruct.Pin = ADCx_CHANNEL_PIN_V; HAL_GPIO_Init(ADCx_CHANNEL_GPIO_PORT_V, &GPIO_InitStruct); /*##-3- Configure the DMA streams ##########################################*/ /* Set the parameters to be configured */ hdma_adc.Instance = ADCx_DMA_STREAM; hdma_adc.Init.Channel = ADCx_DMA_CHANNEL; 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_WORD; hdma_adc.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; hdma_adc.Init.Mode = DMA_CIRCULAR; hdma_adc.Init.Priority = DMA_PRIORITY_HIGH; hdma_adc.Init.FIFOMode = DMA_FIFOMODE_DISABLE; hdma_adc.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL; hdma_adc.Init.MemBurst = DMA_MBURST_SINGLE; hdma_adc.Init.PeriphBurst = DMA_PBURST_SINGLE; HAL_DMA_Init(&hdma_adc); /* Associate the initialized DMA handle to the ADC handle */ __HAL_LINKDMA(hadc, DMA_Handle, hdma_adc); /*##-4- Configure the NVIC for DMA #########################################*/ /* NVIC configuration for DMA transfer complete interrupt */ HAL_NVIC_SetPriority(ADCx_DMA_IRQn, 1, 0); HAL_NVIC_EnableIRQ(ADCx_DMA_IRQn); }
/** * @brief ADC MSP Initialization * This function configures the hardware resources used in this example: * - Peripheral's clock enable * - Peripheral's GPIO Configuration * @param hadc: ADC handle pointer * @retval None */ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) { GPIO_InitTypeDef GPIO_InitStruct; static DMA_HandleTypeDef DmaHandle; /*##-1- Enable peripherals and GPIO Clocks #################################*/ /* Enable GPIO clock */ ADCx_CHANNEL_GPIO_CLK_ENABLE(); /* ADC1 Periph clock enable */ ADCx_CLK_ENABLE(); /* Enable DMA1 clock */ __HAL_RCC_DMA1_CLK_ENABLE(); /*##-2- Configure peripheral GPIO ##########################################*/ /* ADC1 Channel9 GPIO pin configuration */ GPIO_InitStruct.Pin = ADCx_CHANNEL_PIN; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(ADCx_CHANNEL_GPIO_PORT, &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_HIGH; /* Deinitialize & Initialize the DMA for new transfer */ HAL_DMA_DeInit(&DmaHandle); HAL_DMA_Init(&DmaHandle); /* Associate the initialized DMA handle to the the ADC handle */ __HAL_LINKDMA(hadc, DMA_Handle, DmaHandle); /*##-4- Configure the NVIC for DMA #########################################*/ /* NVIC configuration for DMA transfer complete interrupt */ HAL_NVIC_SetPriority(ADCx_DMA_IRQn, 5, 0); HAL_NVIC_EnableIRQ(ADCx_DMA_IRQn); }
/** * @brief ADC MSP Initialization * This function configures the hardware resources used in this example: * - Peripheral's clock enable * - Peripheral's GPIO Configuration * @param hadc: ADC handle pointer * @retval None */ void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) { GPIO_InitTypeDef GPIO_InitStruct; /*##-1- Enable peripherals and GPIO Clocks #################################*/ /* ADC3 Periph clock enable */ ADCx_CLK_ENABLE(); /* Enable GPIO clock ****************************************/ ADCx_CHANNEL_GPIO_CLK_ENABLE(); /*##-2- Configure peripheral GPIO ##########################################*/ /* ADC Channel GPIO pin configuration */ GPIO_InitStruct.Pin = ADCx_CHANNEL_PIN; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(ADCx_CHANNEL_GPIO_PORT, &GPIO_InitStruct); }
/** * @brief ADC MSP Initialization * This function configures the hardware resources used in this example: * - Peripheral's clock enable * - Peripheral's GPIO Configuration * @param huart: UART handle pointer * @retval None */ void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc) { GPIO_InitTypeDef GPIO_InitStruct; /*##-1- Enable peripherals and GPIO Clocks #################################*/ /* ADC3 Periph clock enable */ ADCx_CLK_ENABLE(); /* Enable GPIO clock ****************************************/ ADCx_CHANNEL_GPIO_CLK_ENABLE(); /*##-2- Configure peripheral GPIO ##########################################*/ /* ADC3 Channel8 GPIO pin configuration */ GPIO_InitStruct.Pin = ADCx_CHANNEL_PIN; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(ADCx_CHANNEL_GPIO_PORT, &GPIO_InitStruct); /*##-3- Configure the NVIC #################################################*/ /* NVIC configuration for DMA transfer complete interrupt (USART1_TX) */ HAL_NVIC_SetPriority(ADCx_IRQn, 0, 0); HAL_NVIC_EnableIRQ(ADCx_IRQn); }