⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stm32f10x_adc.c

📁 stm32f10xx的中文译文例程
💻 C
📖 第 1 页 / 共 3 页
字号:
*                       - ADC_Channel_1: ADC信道1被选择
*                       - ADC_Channel_2: ADC信道2被选择
*                       - ADC_Channel_3: ADC信道3被选择
*                       - ADC_Channel_4: ADC信道4被选择
*                       - ADC_Channel_5: ADC信道5被选择
*                       - ADC_Channel_6: ADC信道6被选择
*                       - ADC_Channel_7: ADC信道7被选择
*                       - ADC_Channel_8: ADC信道8被选择
*                       - ADC_Channel_9: ADC信道9被选择
*                       - ADC_Channel_10: ADC信道10被选择
*                       - ADC_Channel_11: ADC信道11被选择
*                       - ADC_Channel_12: ADC信道12被选择
*                       - ADC_Channel_13: ADC信道13被选择
*                       - ADC_Channel_14: ADC信道14被选择
*                       - ADC_Channel_15: ADC信道15被选择
*                       - ADC_Channel_16: ADC信道16被选择
*                       - ADC_Channel_17: ADC信道17被选择
*           (3)Rank:常规组音序器(sequencer)的等级。参数范围是1-16。
*           (4)ADC_SampleTime:将要为所选的信道设置的采样时间
*                    ADC_SampleTime.取值:
*                       - ADC_SampleTime_1Cycles5: 采样时间等于1.5个周期
*                       - ADC_SampleTime_7Cycles5: 采样时间等于7.5个周期
*                       - ADC_SampleTime_13Cycles5: 采样时间等于13.5个周期
*                       - ADC_SampleTime_28Cycles5: 采样时间等于28.5个周期
*                       - ADC_SampleTime_41Cycles5: 采样时间等于41.5个周期
*                       - ADC_SampleTime_55Cycles5: 采样时间等于55.5个周期
*                       - ADC_SampleTime_71Cycles5: 采样时间等于71.5个周期
*                       - ADC_SampleTime_239Cycles5: 采样时间等于239.5个周期
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, u8 ADC_Channel, u8 Rank, u8 ADC_SampleTime)
{
  u32 tmpreg1 = 0, tmpreg2 = 0;

  /* Check the parameters [检查参数] */
  assert_param(IS_ADC_ALL_PERIPH(ADCx));
  assert_param(IS_ADC_CHANNEL(ADC_Channel));
  assert_param(IS_ADC_REGULAR_RANK(Rank));
  assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime));

  /* if ADC_Channel_10 ... ADC_Channel_17 is selected [如果ADC_Channel_10 ... ADC_Channel_17被选择]*/
  if (ADC_Channel > ADC_Channel_9)
  {
    /* Get the old register value [取得旧的寄存器值]*/
    tmpreg1 = ADCx->SMPR1;
    /* Calculate the mask to clear [计算需要清除的标志]*/
    tmpreg2 = SMPR1_SMP_Set << (3 * (ADC_Channel - 10));
    /* Clear the old discontinuous mode channel count [清除过去的不间断模式通道计数器]*/
    tmpreg1 &= ~tmpreg2;
    /* Calculate the mask to set [计算需要置位的标志]*/
    tmpreg2 = (u32)ADC_SampleTime << (3 * (ADC_Channel - 10));
    /* Set the discontinuous mode channel count [设置不间断模式通道计数器]*/
    tmpreg1 |= tmpreg2;
    /* Store the new register value [存储新的寄存器值]*/
    ADCx->SMPR1 = tmpreg1;
  }
  else /* ADC_Channel include in ADC_Channel_[0..9] [ADC_Channel 在 ADC_Channel_[0..9]之间]*/
  {
    /* Get the old register value [取得旧的寄存器值]*/
    tmpreg1 = ADCx->SMPR2;
    /* Calculate the mask to clear [计算需要清除的标志]*/
    tmpreg2 = SMPR2_SMP_Set << (3 * ADC_Channel);
    /* Clear the old discontinuous mode channel count [清除过去的不间断模式通道计数器]*/
    tmpreg1 &= ~tmpreg2;
    /* Calculate the mask to set [计算需要置位的标志]*/
    tmpreg2 = (u32)ADC_SampleTime << (3 * ADC_Channel);
    /* Set the discontinuous mode channel count [设置不间断模式通道计数器]*/
    tmpreg1 |= tmpreg2;
    /* Store the new register value [存储新的寄存器值]*/
    ADCx->SMPR2 = tmpreg1;
  }
  /* For Rank 1 to 6 [序列在1到6之间]*/
  if (Rank < 7)
  {
    /* Get the old register value [取得旧的寄存器值]*/
    tmpreg1 = ADCx->SQR3;
    /* Calculate the mask to clear [计算需要清除的标志]*/
    tmpreg2 = SQR3_SQ_Set << (5 * (Rank - 1));
    /* Clear the old SQx bits for the selected rank [根据选择的序列清除旧的SQx位]*/
    tmpreg1 &= ~tmpreg2;
    /* Calculate the mask to set [计算需要置位的标志]*/
    tmpreg2 = (u32)ADC_Channel << (5 * (Rank - 1));
    /* Set the SQx bits for the selected rank [根据选择的序列置位新的SQx位]*/
    tmpreg1 |= tmpreg2;
    /* Store the new register value [存储新的寄存器值]*/
    ADCx->SQR3 = tmpreg1;
  }
  /* For Rank 7 to 12 [序列在7到12之间]*/
  else if (Rank < 13)
  {
    /* Get the old register value [取得旧的寄存器值]*/
    tmpreg1 = ADCx->SQR2;
    /* Calculate the mask to clear [计算需要清除的标志]*/
    tmpreg2 = SQR2_SQ_Set << (5 * (Rank - 7));
    /* Clear the old SQx bits for the selected rank [根据选择的序列清除旧的SQx位]*/
    tmpreg1 &= ~tmpreg2;
    /* Calculate the mask to set [计算需要置位的标志]*/
    tmpreg2 = (u32)ADC_Channel << (5 * (Rank - 7));
    /* Set the SQx bits for the selected rank [根据选择的序列置位新的SQx位]*/
    tmpreg1 |= tmpreg2;
    /* Store the new register value [存储新的寄存器值]*/
    ADCx->SQR2 = tmpreg1;
  }
  /* For Rank 13 to 16 [序列在13到16之间]*/
  else
  {
    /* Get the old register value [取得旧的寄存器值]*/
    tmpreg1 = ADCx->SQR1;
    /* Calculate the mask to clear [计算需要清除的标志]*/
    tmpreg2 = SQR1_SQ_Set << (5 * (Rank - 13));
    /* Clear the old SQx bits for the selected rank [根据选择的序列清除旧的SQx位]*/
    tmpreg1 &= ~tmpreg2;
    /* Calculate the mask to set [计算需要置位的标志]*/
    tmpreg2 = (u32)ADC_Channel << (5 * (Rank - 13));
    /* Set the SQx bits for the selected rank [根据选择的序列置位新的SQx位]*/
    tmpreg1 |= tmpreg2;
    /* Store the new register value [存储新的寄存器值]*/
    ADCx->SQR1 = tmpreg1;
  }
}

/*******************************************************************************
* 函数名称: ADC_ExternalTrigConvCmd
* 功能描述: 使能或禁止外部触发ADCx转换。
* 输入参数: (1)ADCx:其中x可以是1、2或3,用来选择ADC外围模块.
*           (2)NewState:选中的由外部触发转换的ADC的新状态这个参数可以是:ENABLE或DISABLE。
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void ADC_ExternalTrigConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
{
  /* Check the parameters [检查参数] */
  assert_param(IS_ADC_ALL_PERIPH(ADCx));
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  if (NewState != DISABLE)
  {
    /* Enable the selected ADC conversion on external event [允许外部事件触发选择的ADC转换]*/
    ADCx->CR2 |= CR2_EXTTRIG_Set;
  }
  else
  {
    /* Disable the selected ADC conversion on external event [禁止外部事件触发选择的ADC转换]*/
    ADCx->CR2 &= CR2_EXTTRIG_Reset;
  }
}

/*******************************************************************************
* 函数名称: ADC_GetConversionValue
* 功能描述: 返回常规信道最后的ADCx转换结果。
* 输入参数: ADCx:其中x可以是1、2或3,用来选择ADC外围模块.
* 输出参数: 无
* 返回参数: 数据转换结果.
*******************************************************************************/
u16 ADC_GetConversionValue(ADC_TypeDef* ADCx)
{
  /* Check the parameters [检查参数] */
  assert_param(IS_ADC_ALL_PERIPH(ADCx));

  /* Return the selected ADC conversion value [返回选择的ADC转换值]*/
  return (u16) ADCx->DR;
}

/*******************************************************************************
* 函数名称: ADC_GetDualModeConversionValue
* 功能描述: 返回双重模式下的ADC1和ADC2的最后转换结果
* 输出参数: 无
* 返回参数: 数据转换结果.
*******************************************************************************/
u32 ADC_GetDualModeConversionValue(void)
{
  /* Return the dual mode conversion value [返回双模式转换值]*/
  return (*(vu32 *) DR_ADDRESS);
}

/*******************************************************************************
* 函数名称: ADC_AutoInjectedConvCmd
* 功能描述: 使能/禁止在常规组转换后,被选的ADC进行自动注入组转换。
* 输入参数: (1)ADCx:其中x可以是1、2或3,用来选择ADC外围模块.
*           (2)NewState:选中的进行自动注入转换的ADC新状态这个参数可以是:ENABLE或DISABLE。
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void ADC_AutoInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
{
  /* Check the parameters [检查参数] */
  assert_param(IS_ADC_ALL_PERIPH(ADCx));
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  if (NewState != DISABLE)
  {
    /* Enable the selected ADC automatic injected group conversion [允许选择的ADC自动注入通道组转换]*/
    ADCx->CR1 |= CR1_JAUTO_Set;
  }
  else
  {
    /* Disable the selected ADC automatic injected group conversion [禁止选择的ADC自动注入通道组转换]*/
    ADCx->CR1 &= CR1_JAUTO_Reset;
  }
}

/*******************************************************************************
* 函数名称: ADC_InjectedDiscModeCmd
* 功能描述: 使能/禁止指定ADC注入组信道的非连续模式。
* 输入参数: (1)ADCx:其中x可以是1、2或3,用来选择ADC外围模块.
*           (2)NewState:被选中的,注入组信道上为非连续模式的ADC的新状态这个参数可以是:ENABLE或DISABLE。
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void ADC_InjectedDiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
{
  /* Check the parameters [检查参数] */
  assert_param(IS_ADC_ALL_PERIPH(ADCx));
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  if (NewState != DISABLE)
  {
    /* Enable the selected ADC injected discontinuous mode [允许选的ADC通道注入连续转换模式]*/
    ADCx->CR1 |= CR1_JDISCEN_Set;
  }
  else
  {
    /* Disable the selected ADC injected discontinuous mode [禁止选的ADC通道注入连续转换模式]*/
    ADCx->CR1 &= CR1_JDISCEN_Reset;
  }
}

/*******************************************************************************
* 函数名称: ADC_ExternalTrigInjectedConvConfig
* 功能描述: 为注入信道转换配置ADCx外部触发
* 输入参数: (1)ADCx:其中x可以是1、2或3,用来选择ADC外围模块.
*           (2)ADC_ExternalTrigInjecConv:开始注入转换的ADC触发器
*                    ADC_ExternalTrigInjecConv 取值:
*                       - ADC_ExternalTrigInjecConv_T1_TRGO: 定时器1TRGO事件作为注入转换(ADC1,ADC2,ADC3)的外部触发器
*                       - ADC_ExternalTrigInjecConv_T1_CC4: 定时器1捕获比较4作为注入转换(ADC1,ADC2,ADC3)的外部触发器
*                       - ADC_ExternalTrigInjecConv_T2_TRGO: 定时器2TRGO事件作为注入转换(ADC1,ADC2,ADC3)的外部触发器
*                       - ADC_External TrigInjecConv_T2_CC1: 定时器2捕获比较1作为注入转换(ADC1,ADC2,ADC3)的外部触发器
*                       - ADC_ExternalTrigInjecConv_T3_CC4: 定时器3捕获比较4作为注入转换(ADC1,ADC2,ADC3)的外部触发器
*                       - ADC_ExternalTrigInjecConv_T4_TRGO: 定时器4TRGO事件作为注入转换(ADC1,ADC2,ADC3)的外部触发器
*                       - ADC_ExternalTrigInjecConv_Ext_IT15_TIM8_CC4: 外部中断15或者timer8比较事件作为注入转换(ADC1,ADC2,ADC3)的外部触发器
*                       - ADC_External TrigInjecConv_T4_CC3: timer4比较3事件作为注入转换(只ADC3)的外部触发器
*                       - ADC_External TrigInjecConv_T8_CC2: timer8比较2事件作为注入转换(只ADC3)的外部触发器
*                       - ADC_External TrigInjecConv_T8_CC4: timer8比较4事件作为注入转换(只ADC3)的外部触发器
*                       - ADC_ExternalTrigInjecConv_T5_TRGO: 定时器5 TRGO 事件作为注入转换(只ADC3)的外部触发器
*                       - ADC_External TrigInjecConv_T5_CC4: timer5比较4事件作为注入转换(只ADC3)的外部触发器
*                       - ADC_ExternalTrigInjecConv_无: 注入转换由软件启动,而不是由外部触发器启动
* 输出参数: 无
* 返回参数: 无
*******************************************************************************/
void ADC_ExternalTrigInjectedConvConfig(ADC_TypeDef* ADCx, u32 ADC_ExternalTrigInjecConv)
{
  u32 tmpreg = 0;

  /* Check the parameters [检查参数] */
  assert_param(IS_ADC_ALL_PERIPH(ADCx));
  assert_param(IS_ADC_EXT_INJEC_TRIG(ADC_ExternalTrigInjecConv));

  /* Get the old register value [取得旧的寄存器值]*/
  tmpreg = ADCx->CR2;
  /* Clear the old external event selection for injected group [清除选择的注入通道群的外部触发事件]*/
  tmpreg &= CR2_JEXTSEL_Reset;
  /* Set the external event selection for injected group [置位选择的注入通道群的外部触发事件]*/
  tmpreg |= ADC_ExternalTrigInjecConv;
  /* Store the new register value [存储新的寄存器值]*/
  ADCx->CR2 = tmpreg;
}

/*******************************************************************************
* 函数名称: ADC_ExternalTrigInjectedConvCmd
* 功能描述: 通过外部触发器使能/禁止ADCx注入信道转换
* 输入参数: (1)ADCx:其中x可以是1、2或3,用来选择ADC外围模块.
*           (2)NewState:选中的用于启动注入转换的ADC外部触发器。这个参数可以是:ENABLE或DISABLE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -