AnsweredAssumed Answered

ADC1 STM32F0

Question asked by hakim.soni on Jan 30, 2014
Latest reply on Feb 4, 2014 by hakim.soni
Hi all,
I just started working with STM32F0. I want to try ADC1 in this board but I find some trouble. I want to turn on the LED (PC8 and PC9) by using ADC as benchmark, so when ADC1 reach 2000 bit or 7D0 then LED PC8 and PC9 will tun on.
I've create ADC code and compile it using cocoox, no error. but when I download it to the flash this kode not working. I've try to give input 0-3,2volt to ADC1 (PA1) and the LED is not turn on.
this is the code
01.#include "stm32f0xx_gpio.h"
02.#include "stm32f0xx_rcc.h"
03.#include "stm32f0xx_conf.h"
04.#include "stm32f0xx_adc.h"
05. 
06.#define ADC_CFGR1_CONT ((uint32_t)0x00002000)       /*!< Continuous Conversion */
07. 
08. 
09.void pinout_config(void) {
10.GPIO_InitTypeDef GPIO_InitStruct;
11. 
12.RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
13.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1;     // that's ADC1 (PA1 on STM32)
14.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
15.GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
16.GPIO_Init(GPIOA, &GPIO_InitStruct);
17. 
18.ADC_Cmd (ADC1,ENABLE);  //enable ADC1
19.}
20. 
21.void led_config(void){
22.GPIO_InitTypeDef GPIO_InitStruct;
23.RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
24. 
25./*Configure GPIO pin */
26.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;
27.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
28.GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
29.GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
30.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
31.GPIO_Init(GPIOC, &GPIO_InitStruct);
32.}
33. 
34.int main(void)
35.{
36.    pinout_config();
37.    led_config();
38. 
39. 
40.    while(1)
41.    {
42.        void LED_set (void)
43.        {
44.        if(ADC1>2000)
45.        {
46.        (GPIOC->BSRR = GPIO_Pin_8);
47.        (GPIOC->BSRR = GPIO_Pin_9);
48.        }
49.        else {
50.        (GPIOC->BRR = GPIO_Pin_8);
51.        (GPIOC->BRR = GPIO_Pin_9);
52.        }
53.        }
54.    }
55.}

can someone tell me what is wrong with the code?
thank you for your help

Outcomes