AnsweredAssumed Answered

[SOLVED] STM32l152c Discovery board, Cant see my problem getting ADC working

Question asked by gardner.julian on Sep 22, 2015
Latest reply on Sep 25, 2015 by gardner.julian
Initialisation call from main
      adc_setup_data.adc_block = ADC1;
      adc_setup_data.adc_channel = 1;
      adc_setup_data.adc_number_of_bits = ADC_Resolution_12b;
      adc_setup_data.adc_sample_time = ADC_SampleTime_16Cycles;
      adc_setup_data.adc_GPIOx = GPIOA;
      adc_setup_data.adc_gpio_pin = GPIO_Pin_1;
      adc_init( adc_poll_callback, &adc_setup_data);
 
The routine itself
int adc_init( adc_poll_data poll_cb, void *user_data)
{
    ADC_CommonInitTypeDef prescale;
    ADC_InitTypeDef ADC_InitStructure;
    GPIO_InitTypeDef GPIO_InitStructure;
    adc_setup *setup = user_data;
 
    if( !IS_ADC_ALL_PERIPH(setup->adc_block)) {
        return -1;
    }
 
    if( !IS_ADC_CHANNEL(setup->adc_channel)) {
        return -1;
    }
 
    if( !IS_ADC_RESOLUTION(setup->adc_number_of_bits)) {
        return -1;
    }
 
    if( !IS_ADC_SAMPLE_TIME( setup->adc_sample_time)) {
 
    }
 
    /* Common Prescaler for ADC */
    prescale.ADC_Prescaler = ADC_Prescaler_Div4;        /* ADC_Prescaler_Div1, ADC_Prescaler_Div2 or ADC_Prescaler_Div4 */
    ADC_CommonInit(&prescale);
 
    if( setup->adc_block == ADC1) {
        RCC_PCLK2Config(RCC_HCLK_Div16);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
    }
    else {
        return -1;
    }
 
    adc_data.adc.ADCx = setup->adc_block;
    adc_data.adc.adc_channel = setup->adc_channel;
    adc_data.adc.adc_last_value = (1<<12) + 1;
    adc_data.adc.adc_differential = 8;
 
    adc_data.queue = queue_create(5);
    adc_data.running = FALSE;
    adc_data.poll_callback = poll_cb;
    adc_data.poll_user_data = user_data;
 
    // Init the GPIO with the structure
    GPIO_InitStructure.GPIO_Pin = setup->adc_gpio_pin;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_Init(setup->adc_GPIOx, &GPIO_InitStructure);
 
    ADC_DeInit(setup->adc_block);
 
    /* Configuration ------------------------------------------------------*/
    ADC_InitStructure.ADC_Resolution = setup->adc_number_of_bits;
    ADC_InitStructure.ADC_ScanConvMode = DISABLE;
    ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConvEdge_None;
    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
    ADC_InitStructure.ADC_NbrOfConversion = 1;
    ADC_Init(setup->adc_block, &ADC_InitStructure);
 
    //configure channel
    ADC_RegularChannelConfig(setup->adc_block, setup->adc_channel, 1, setup->adc_sample_time);
    //Enable channel
    ADC_Cmd(setup->adc_block, ENABLE);
 
    return 1;
}

Ive walked this code and cannot see what im doing wrong, but every read from the ADC os 0x000

Any help

joolz

Outcomes