示例#1
0
 void ADC_CommonInit(ADC_CommonInitTypeDef* ADC_CommonInitStruct)
{
  uint32_t tmpreg1 = 0;
  /* Check the parameters */
  assert_param(IS_ADC_MODE(ADC_CommonInitStruct->ADC_Mode));
  assert_param(IS_ADC_PRESCALER(ADC_CommonInitStruct->ADC_Prescaler));
  assert_param(IS_ADC_DMA_ACCESS_MODE(ADC_CommonInitStruct->ADC_DMAAccessMode));
  assert_param(IS_ADC_SAMPLING_DELAY(ADC_CommonInitStruct->ADC_TwoSamplingDelay));
  /*---------------------------- ADC CCR Configuration -----------------*/
  /* Get the ADC CCR value */
  tmpreg1 = ADC->CCR;
  
  /* Clear MULTI, DELAY, DMA and ADCPRE bits */
  tmpreg1 &= CR_CLEAR_MASK;
  
  /* Configure ADCx: Multi mode, Delay between two sampling time, ADC prescaler,
     and DMA access mode for multimode */
  /* Set MULTI bits according to ADC_Mode value */
  /* Set ADCPRE bits according to ADC_Prescaler value */
  /* Set DMA bits according to ADC_DMAAccessMode value */
  /* Set DELAY bits according to ADC_TwoSamplingDelay value */    
  tmpreg1 |= (uint32_t)(ADC_CommonInitStruct->ADC_Mode | 
                        ADC_CommonInitStruct->ADC_Prescaler | 
                        ADC_CommonInitStruct->ADC_DMAAccessMode | 
                        ADC_CommonInitStruct->ADC_TwoSamplingDelay);
                        
  /* Write to ADC CCR */
  ADC->CCR = tmpreg1;
}
示例#2
0
/**
  * @brief  Set ADC sample hold time and prescaler output.
  * @param  Sample_HoldTime: Select ADC sample hold time.
  *   This parameter can be one of the following values:
  *   ADC_HOLD_CLK_8, ADC_HOLD_CLK_16, ADC_HOLD_CLK_24, ADC_HOLD_CLK_32,
  *   ADC_HOLD_CLK_64, ADC_HOLD_CLK_128, ADC_HOLD_CLK_512.
  * @param  Prescaler_Output: Select ADC prescaler output.
  *   This parameter can be one of the following values:
  *   ADC_FC_DIVIDE_LEVEL_1, ADC_FC_DIVIDE_LEVEL_2, ADC_FC_DIVIDE_LEVEL_4,
  *   ADC_FC_DIVIDE_LEVEL_8, ADC_FC_DIVIDE_LEVEL_16.
  * @retval None.
  */
void ADC_SetClk(uint32_t Sample_HoldTime, uint32_t Prescaler_Output)
{
    /* Check the parameters */
    assert_param(IS_ADC_HOLD_TIME(Sample_HoldTime));
    assert_param(IS_ADC_PRESCALER(Prescaler_Output));
    /* Set ADCLK */
    TSB_AD->CLK = Sample_HoldTime + Prescaler_Output;
}
示例#3
0
/**
  * @brief  Set ADC prescaler output(SCLK) of the specified ADC unit.
  * @param  ADx: Select ADC unit
  *   This parameter can be one of the following values:
  *     For M370:   TSB_ADA, TSB_ADB
  *     For M372/3/4:  TSB_ADB
  * @param  Sample_HoldTime: Select ADC sample hold time.
  *   This parameter can be one of the following values:
  *     ADC_HOLD_FIX
  * @param  Prescaler_Output: Select ADC prescaler output.
  *   This parameter can be one of the following values:
  *     ADC_FC_DIVIDE_LEVEL_NONE,   ADC_FC_DIVIDE_LEVEL_2,
  *     ADC_FC_DIVIDE_LEVEL_4,      ADC_FC_DIVIDE_LEVEL_8,
  *     ADC_FC_DIVIDE_LEVEL_16
  * @retval None
  */
void ADC_SetClk(TSB_AD_TypeDef * ADx, uint32_t Sample_HoldTime, ADC_PRESCALER Prescaler_Output)
{
    uint32_t tmp = 0U;

    /* Check the parameters */
    assert_param(IS_ADC_UNIT(ADx));
    assert_param(IS_ADC_SAMPLEHOLD(Sample_HoldTime));
    assert_param(IS_ADC_PRESCALER(Prescaler_Output));

    tmp = Sample_HoldTime | Prescaler_Output;
    ADx->CLK = tmp;
}