STM32G070的AD调试

       前几天在调试STM32G070的AD功能,采集电池电压去计算电池剩余电量,开始用通道1,没有问题,后来硬件改版变成了通道16,发现AD采用异常,现在把调试过程记录如下,希望能够帮助其他人吧。

1、首先看通道16能不能用

G070一共19个采样通道,其中三个内部通道(温度、基准、Vbat),16个外部通道,如下图所示:

 从图可知,ADC_IN16是可用的外部通道。

2、既然通道没问题,那就只能看AD的配置了

 在通道配置这章,说的很清楚了Sequencer fully configurable模式只能配置8个通道,并且只能从channel 0和channel 14中选择。

3、AD通道模式配置

 看库函数:

  * @rmtoll CFGR     CHSELRMOD      LL_ADC_REG_SetSequencerConfigurable
  * @param  ADCx ADC instance
  * @param  Configurability This parameter can be one of the following values:
  *         @arg @ref LL_ADC_REG_SEQ_FIXED
  *         @arg @ref LL_ADC_REG_SEQ_CONFIGURABLE
  * @retval None
  */
__STATIC_INLINE void LL_ADC_REG_SetSequencerConfigurable(ADC_TypeDef *ADCx, uint32_t Configurability)
{
  MODIFY_REG(ADCx->CFGR1, ADC_CFGR1_CHSELRMOD, Configurability);
}

 参数说明:


#define LL_ADC_REG_SEQ_FIXED               (0x00000000UL)         /*!< Sequencer configured to fully configurable: sequencer length and each rank affectation to a channel are configurable. Refer to description of function @ref LL_ADC_REG_SetSequencerLength(). */
#define LL_ADC_REG_SEQ_CONFIGURABLE        (ADC_CFGR1_CHSELRMOD)  /*!< Sequencer configured to not fully configurable: sequencer length and each rank affectation to a channel are fixed by channel HW number. Refer to description of function @ref LL_ADC_REG_SetSequencerChannels(). */

根据参数说明,配置如下:

LL_ADC_REG_SetSequencerConfigurable(ADC1, LL_ADC_REG_SEQ_CONFIGURABLE);

测试发现不行,AD还是不对,问题在哪里?看了AD其它配置,没有问题,那问题应该还是在通道模式选择这里。

查看寄存器:

0是Sequencer configured to not fully configurable

1是Sequencer configured to fully configurable

但是库里面给的说明确实:

0是Sequencer configured to fully configurable

1是Sequencer configured to not fully configurable

配置如下:

LL_ADC_REG_SetSequencerConfigurable(ADC1, LL_ADC_REG_SEQ_FIXED);

测试正常,我的库版本是LL库V1.0.0。

 

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值