cancel
Showing results for 
Search instead for 
Did you mean: 

Adc channel problem

teijo
Associate II
Posted on November 05, 2013 at 12:59

Hello,

I

'm using stm32f

417vg chip and arm-none-eabi-gcc compiler

(and gd

b

)

.

I try to get adc

to read 14

an

alog

input

channels

.

Channels 1, 2

, 3

values are fine, b

ut

wh

en i

re

ad ch

annel

4

value

do

e

sn't change at all.

I use code below:

typedef struct {

    GPIO_TypeDef* port;

    uint32_t pin;

}gpioConfigs_t;

static gpioConfigs_t gpioConfig[] = {

    {GPIOA,GPIO_Pin_1},

    {GPIOA,GPIO_Pin_2},

    {GPIOA,GPIO_Pin_3},

    {GPIOA,GPIO_Pin_4},

    {GPIOA,GPIO_Pin_5},

    {GPIOA,GPIO_Pin_6},

    {GPIOA,GPIO_Pin_7},

    {GPIOB,GPIO_Pin_0},

    {GPIOB,GPIO_Pin_1},

    {GPIOC,GPIO_Pin_0},

    {GPIOC,GPIO_Pin_1},

    {GPIOC,GPIO_Pin_2},

    {GPIOC,GPIO_Pin_3},

    {GPIOC,GPIO_Pin_4}

};

void internalAdc_init2(void)

{

    GPIO_InitTypeDef      GPIO_InitStructure;

    ADC_CommonInitTypeDef ADC_CommonInitStructure;

    ADC_InitTypeDef       ADC_InitStructure;

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE);

    for(i = 0; i < INTERNAL_ADC_CHANNELS; i++){

            GPIO_InitStructure.GPIO_Pin = gpioConfig[i].pin;

            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;

            GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;

            GPIO_Init(gpioConfig[i].port, &GPIO_InitStructure);

        }

    ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;

    ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;

    ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;

    ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;

    ADC_CommonInit(&ADC_CommonInitStructure);

    /* ADC3 Init */

    ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

    ADC_InitStructure.ADC_ScanConvMode = DISABLE;

    ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

    ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;

    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

    ADC_InitStructure.ADC_NbrOfConversion = 1;

    ADC_Init(ADC3, &ADC_InitStructure);

    /* Enable ADC3 */

    ADC_Cmd(ADC3, ENABLE);

}

uint16_t readAdc(uint8_t channel)

{

    uint16_t res, val = 0;

    ADC_RegularChannelConfig(ADC3, channel, 1, ADC_SampleTime_3Cycles);

    ADC_SoftwareStartConv(ADC3);

    while(ADC_GetFlagStatus(ADC3, ADC_FLAG_EOC) == RESET);

    val = ADC_GetConversionValue(ADC3);

    res = val >> 4;

    return res;

}

from app ->

uint16_t test

Data;

testData = readAdc(1); /*

ok

*/

testData = readAdc(2); /* ok */

testData = readAdc(3);/*

ok *

/

testData = readAdc(4);/* This value

d

oes

not ch

an

ge

*/

2 REPLIES 2
Posted on November 05, 2013 at 14:05

PA4 ADC12_IN4 has NO associativity with ADC3 (just 1 and 2), refer to the

http://www.st.com/web/catalog/mmc/FM141/SC1169/SS1577/LN11/PF252139

.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
teijo
Associate II
Posted on November 05, 2013 at 15:41

Ahh i was missread specs for that part. Thank you very much for help!