cancel
Showing results for 
Search instead for 
Did you mean: 

ADC for single channel free run

sky_brake
Associate II
Posted on January 24, 2014 at 04:13

hi.. I'm working with STM32F0 and I'm trying to create

ADC on STM32 for single channel free run but it doesn't work. Can someone help me to find what is wrong in this code.

thank you for helping me

#include ''stm32f0xx_gpio.h''
#include ''stm32f0xx_rcc.h''
#include ''stm32f0xx_conf.h''
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
int i,j;
/* Blink a LED, blink speed is set by ADC value */
void ADC_simple(void)
{
// init for GPIO (LED)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 ; // two LED
GPIO_Init(GPIOB, &GPIO_InitStructure);
// input of ADC
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ; // that's ADC1 (PA1 on STM32)
GPIO_Init(GPIOA, &GPIO_InitStructure);
//clock for ADC (max 14MHz --> 72/6=12MHz)
RCC_ADCCLKConfig (RCC_PCLK2_Div6);
// enable ADC system clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
// define ADC config
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_RegularChannelConfig(ADC1,ADC_Channel_1, 1,ADC_SampleTime_28Cycles5); // define regular conversion config
ADC_Init ( ADC1, &ADC_InitStructure); //set config of ADC1
// enable ADC
ADC_Cmd (ADC1,ENABLE); //enable ADC1
// ADC calibration
ADC_ResetCalibration(ADC1); // Reset previous calibration
while(ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1); // Start new calibration
while(ADC_GetCalibrationStatus(ADC1));
// start conversion
ADC_Cmd (ADC1,ENABLE); //enable ADC1
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
// debug information
RCC_ClocksTypeDef forTestOnly;
RCC_GetClocksFreq(&forTestOnly); 
j= 50000;
while(1)
{
GPIO_WriteBit(GPIOB,GPIO_Pin_8,Bit_RESET);
GPIO_WriteBit(GPIOB,GPIO_Pin_9,Bit_SET);
for (i=0;i

1 REPLY 1
raptorhal2
Lead
Posted on January 24, 2014 at 16:00

main() and part of the ADC_simple function are not visible, so we cannot tell if there is anything wrong with monitoring the conversion result.

How do you know it is not working ?

Cheers, Hal