cancel
Showing results for 
Search instead for 
Did you mean: 

Adc value

gregorydrck5
Associate
Posted on February 23, 2013 at 15:46

Hello,

I'm trying to get back the value of the conversion from adc1. But, nothing happend. Could you help me ? Thank you,

/* Includes */
#include <
stddef.h
>
#include ''stm32f10x.h''
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
int main(void)
{
float a;
GPIO_StructInit (& GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOC , &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA , &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConv =ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 1;
ADC_Init(ADC1 , &ADC_InitStructure);
// Configure ADC_IN6
ADC_RegularChannelConfig(ADC1 , ADC_Channel_6 , 1,ADC_SampleTime_55Cycles5);
// Enable ADC
ADC_Cmd(ADC1 , ENABLE);
// Check the end of ADC1 reset calibration register
while(ADC_GetResetCalibrationStatus(ADC1));
// Start ADC1 calibration
ADC_StartCalibration(ADC1);
// Check the end of ADC1 calibration
while(ADC_GetCalibrationStatus(ADC1));
a = ADC_GetConversionValue(ADC1);
}

1 REPLY 1
Posted on February 23, 2013 at 17:01

You need to be enabling clocks before configuring IOs dependent on those clocks

The value isn't returned as a float, it comes back as an integer which you then need to scale against your reference/full-scale voltage.

You'll probably want to start a conversion, and then wait for it (not calibration)
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..