Exemplo n.º 1
0
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();
}
Exemplo n.º 2
0
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 */
  }
}
Exemplo n.º 3
0
Arquivo: adc.c Projeto: pacabot/zhonx3
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 */
    }
}
Exemplo n.º 4
0
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++;
		  }
	}