AnsweredAssumed Answered

how can i get value from IN1 and IN2 from ADC in CMSIS

Question asked by hossein hosseini on Dec 18, 2017
Latest reply on Jan 28, 2018 by hossein hosseini

hi.

i wrote a code for ADC1 , and i could get value from ADC1_channel_1 (IN1)  but i cant get value of Channel_2 and show both of two value  on LCD in same time.

I dont know which function can I use to get both value . in this code i have just Channel_1 value .

i use IAR and stm32f103RE.

(i know the code is long , but i sholud put it for you , so thanks)

 

#include "stm32f10x.h"
#include "stm32f10x_gpio.h"  // for Enable LCD
#include "stm32f10x_rcc.h"   //for Enable LCD
#include "stm32f10x_adc.h"
#include "LCDLib.h"
#include "delay.h"

void init_adc(void);
int adcValue = 5000 ;

int main()
{
  init_adc();
  lcd_init();
  lcdPutString ("Believe Your Dreams.");
   
  while(1){
    
   ADC_SoftwareStartConvCmd(ADC1, ENABLE);
   adcValue = ADC_GetConversionValue(ADC1);
   
   lcdGoxy( 1 ,  3);
   lcdPutString ("           ");
   lcdGoxy( 1 ,  3);
   lcdPutInt(adcValue);

  
   delay_ms(200);  


   ADC_SoftwareStartConvCmd(ADC1, ENABLE);
   adcValue = ADC_GetConversionValue(ADC1);
   
   lcdGoxy( 1 ,  4);
   lcdPutString ("           ");
   lcdGoxy( 1 ,  4);
   lcdPutInt(adcValue);
   
   delay_ms(200);   
  }
}

void init_adc(void){
 
    GPIO_InitTypeDef GPIO_InitStructure;
    ADC_InitTypeDef ADC_InitStructure;

    RCC_ADCCLKConfig (RCC_PCLK2_Div6);
        
    /* Enable ADC1 and GPIOA clock */
    RCC_APB2PeriphClockCmd ( RCC_APB2Periph_GPIOA | RCC_APB2Periph_ADC1 ,    ENABLE ) ;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
    ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
    ADC_InitStructure.ADC_NbrOfChannel = 2;
    ADC_InitStructure.ADC_ScanConvMode = DISABLE;
    ADC_Init(ADC1, &ADC_InitStructure);
    ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_13Cycles5);
    ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 2, ADC_SampleTime_13Cycles5);
        
    ADC_Cmd ( ADC1 , ENABLE ) ;

      
    ADC_ResetCalibration(ADC1);
    while(ADC_GetResetCalibrationStatus(ADC1));
    ADC_StartCalibration(ADC1);
    while(ADC_GetCalibrationStatus(ADC1));
        
        
}

Outcomes