历史上的今天
今天是:2024年09月09日(星期一)
2021年09月09日 | STM32F0xx的ADC配置
2021-09-09 来源:eefocus
STM32F0xx系列单片机基于ST官方标准库V1.5.0的ADC功能的配置
ADC.c文件
#include "ADC.h"
uint32_t ADC1ConvertedValue = 0, ADC1ConvertedVoltage = 0;
void ADC_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
//端口配置
// GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //50M时钟速度
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void ADC_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
ADC_DeInit(ADC1);
ADC_StructInit(&ADC_InitStructure);
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
// ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Backward;
ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward; //向上扫描
ADC_Init(ADC1, &ADC_InitStructure);
ADC_ChannelConfig(ADC1, ADC_Channel_1, ADC_SampleTime_239_5Cycles);
ADC_GetCalibrationFactor(ADC1);
ADC_Cmd(ADC1, ENABLE);
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADRDY));
// ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
//开始校准状态
ADC_StartOfConversion(ADC1);
}
uint32_t ADC_Read(void)
{
/* Test EOC flag */
while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
/* Get ADC1 converted data */
ADC1ConvertedValue = ADC_GetConversionValue(ADC1);
/* Compute the voltage */
ADC1ConvertedVoltage = (ADC1ConvertedValue * 3300)/0xFFF;
return ADC1ConvertedVoltage;
}
ADC.h文件
#ifndef __ADC_H
#define __ADC_H
#include "stm32f0xx.h"
#include "stm32f0xx_adc.h"
//extern uint16_t ADC1ConvertedValue , ADC1ConvertedVoltage ;
//硬件初始化
void ADC_GPIO_Configuration(void); //AD相关初始化
void ADC_Configuration(void);
uint32_t ADC_Read(void);
#endif
main.c文件
#include "main.h"
#include "stm32f0xx_it.h"
#include "USART.h"
#include "ADC.h"
uint32_t ADC_value;
int main(void)
{
ADC_GPIO_Configuration();
ADC_Configuration();
while (1)
{
ADC_value = ADC_Read();
USART_printf( USART2, "rn %d rn", ADC_value );
}
}
史海拾趣
|
在柏林推出的DVB T(地面数字广播)数字电视也已经影响到汽车娱乐系统中的电视接收。现在,汽车电视接收机不仅能够接收模拟电视信号(它仍将在城市以外的地区继续存在数年),而且也能够接收和处理DVB T信号。Hirschmann Electronic ...… 查看全部问答> |
|
1 引 言 洗片机是各医院影像科的必需设备。医院影像科每天要冲洗大量的x-射线透射胶片,工作量大,且洗片操作有一定难度,对操作人员专业技术要求高,另外,洗片时化学药液对人体有伤害。因此,目前医院大多采用医用自动洗片机。进口的 ...… 查看全部问答> |
|
我使用 ARM 2440开发板, 使用WINCE 5.0 (中文)OS, 现在想实验软键盘 汉字输入 和手写 输入。 请前辈们 描述一下实现 思路。 … 查看全部问答> |
|
void InitSio(void) { u16 RELOAD_COUNT = 0; //使用独立波特率发生器作为波特率发生器 S2CON = 0x50;  ...… 查看全部问答> |




