2017-12-18 12:20 PM
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)
&sharpinclude 'stm32f10x.h'
&sharpinclude 'stm32f10x_gpio.h' // for Enable LCD&sharpinclude 'stm32f10x_rcc.h' //for Enable LCD&sharpinclude 'stm32f10x_adc.h'&sharpinclude 'LCDLib.h'&sharpinclude '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)); }#adc1
2018-01-28 02:39 AM
we can use DMA to get all of the channels value.