stm32 ADC详细配置笔记(1)

//配置ADC
void ADC_Config(void)
{
ADC_InitTypeDef ADC_InitStructure;
// ADC1 and TIM1 Periph clock enable
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

// ADC1 DeInit
ADC_DeInit(ADC1);
/* Initialize ADC structure */
ADC_StructInit(&ADC_InitStructure);
/* Configure the ADC1 in continous mode withe a resolution equal to 12 bits */
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_TRGO;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_ChannelConfig(ADC1, ADC_Channel_0 | ADC_Channel_4 | ADC_Channel_5 | ADC_Channel_6 , ADC_SampleTime_7_5Cycles);
ADC_OverrunModeCmd(ADC1, ENABLE);
/* ADC Calibration */
ADC_GetCalibrationFactor(ADC1);
/* ADC DMA request in circular mode */
ADC_DMARequestModeConfig(ADC1, ADC_DMAMode_Circular);
/* Enable ADC_DMA */
ADC_DMACmd(ADC1, ENABLE);
/* Enable the ADC peripheral */
ADC_Cmd(ADC1, ENABLE);
/* Wait the ADRDY flag */
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADRDY));
/* ADC1 regular Software Start Conv */
ADC_StartOfConversion(ADC1);
}

//配置GPIO

// Configure PA0-5 in AN mode
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);

注意:
1.测试时要给ADC模块供电(独立于开发板)该电压为基准电压;
2.ADC配置各种使能顺序不能错乱;
3.DMA的设备地址依据参考手册;
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
配置STM32F103的ADC3,可以按照以下步骤进行操作: 1. 首先,包含头文件"adc.h",并定义ADC的检测采样和显示变量。 2. 设置ADC的模式为独立模式,扫描模式为使能,连续模式为使能,外部触发转换方式为软件触发,数据对齐方式为右对齐,通道数为2个通道。 3. 使用ADC_Init函数来初始化ADC1,传入ADC1的配置结构体ADC1_InitStructure。 4. 配置ADC的中断,注意ADC1和ADC2共用同一个中断向量,而ADC3有自己的中断向量。规则和注入组转换结束时能产生中断,当模拟看门狗状态位被设置时也能产生中断。它们都有独立的中断使能位。 以上是配置STM32F103的ADC3的步骤。 #### 引用[.reference_title] - *1* [STM32F103三路ADC同步转换带有DMA功能](https://blog.csdn.net/qq_38664794/article/details/82917230)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [STM32F03学习笔记ADC配置(含DMA配置)](https://blog.csdn.net/qq_26918203/article/details/107641424)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值