AnsweredAssumed Answered

Cannot re-open the ADC-driver

Question asked by nico engel on Jun 22, 2012
Latest reply on Jun 26, 2012 by nico engel

With the code below I open the adc, start reading adc and after than I close the adc.

 

At the first and the second call of my adc calls I get the correct measured values. But on third time I cannot open the adc driver.

 

Than the function “_adc_open” in kernel-file adc.c return me the value “ADC_ERROR_OPENED” (cannot open more than one instance of ADC driver).

 

Does anyone have an idea what is going wrong here? Do I have a mistake by closing the driver?

 

Thank you for replay.

 

const ADC_INIT_CHANNEL_STRUCT adc_channel_param ={    ADC0_SOURCE_AD0, /* physical ADC channel */    ADC_CHANNEL_START_TRIGGERED,    1,              /* number of samples in one run sequence */    0,              /* time offset from trigger point in us */    300000,         /* period in us (= 0.3 sec) */    0x10000,        /* scale range of result (not used now) */    1,              /* circular buffer size (sample count) */    ADC_PDB_TRIGGER,/* logical trigger ID that starts this ADC channel */};uint32_t adc_get_raw(void){    ADC_RESULT_STRUCT adc_data;    MQX_FILE_PTR adc_fp = NULL;    MQX_FILE_PTR channel_input_fp = NULL;    //!___open__________________________________________________________________    printf("Opening %s ...", MY_ADC);    adc_fp = fopen(MY_ADC, (const char*)&adc_init_sruct);    if(adc_fp != NULL)        printf("done\n");    else    {        printf("failed\n");        return 0;    }    printf("Opening channel ...");    channel_input_fp= fopen(MY_ADC "channel",(const char*)&adc_channel_param);    if(channel_input_fp != NULL)        printf("done\n");    else    {        printf("failed\n");        return 0;    }    _time_delay(500);    //!___start_measurement_____________________________________________________    ioctl(adc_fp, ADC_IOCTL_FIRE_TRIGGER, (pointer) MY_TRIGGER);    //!___measure_______________________________________________________________ if (read(channel_input_fp, &adc_data, sizeof(adc_data) )) {  printf("ADC: %4d \n", adc_data.result); }    if (IO_OK == ioctl (channel_input_fp, ADC_IOCTL_STOP_CHANNELS, NULL))    {        printf("stopped\n");    }    else    {        printf("failed\n");    }    //!___close_________________________________________________________________  //! close all ADC channels    printf("Close ADC channel...");    if ( fclose(channel_input_fp) == MQX_OK )        printf("ok\n");    printf("Close ADC driver...");    if ( fclose(adc_fp) == MQX_OK )        printf("ok\n");    else if ( fclose(adc_fp) == ADC_ERROR_NONEMPTY )     printf("--> ADC_ERROR_NONEMPTY --> failed\n");    else        printf("failed\n");    return adc_data.result;}

 

This is the debug output:

Opening adc0: ...done
Opening channel ...done
ADC: 2049
stopped
Close ADC channel...ok
Close ADC driver...ok


Opening adc0: ...done
Opening channel ...done
ADC: 2034
stopped
Close ADC channel...ok
Close ADC driver...ok

Opening adc0: ...done
Opening channel ...failed

Opening adc0: ...failed

....

 

Outcomes