Page 1 of 1

STM32F4xx ADC Driver not working

Posted: Tue Feb 14, 2017 4:22 pm
by Tabulous
Start the ADC like this, trying to run in continuous conversion mode.

Code: Select all

static const ADCConversionGroup adcgrpcfg = {
  TRUE,
  ADC_GRP1_NUM_CHANNELS,
  adcendcallback,
  adcerrorcallback,
  /* HW dependent part.*/
  0,
  ADC_CR2_SWSTART,
  ADC_SMPR2_SMP_AN5(ADC_SAMPLE_56) |
  ADC_SMPR2_SMP_AN6(ADC_SAMPLE_56) |
  ADC_SMPR2_SMP_AN7(ADC_SAMPLE_56) |
  ADC_SMPR2_SMP_AN8(ADC_SAMPLE_56) |
  ADC_SMPR2_SMP_AN9(ADC_SAMPLE_56) ,
  0,
  ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),
  0,
  ADC_SQR3_SQ1_N(ADC_CHANNEL_IN7) |
  ADC_SQR3_SQ2_N(ADC_CHANNEL_IN8) |
  ADC_SQR3_SQ3_N(ADC_CHANNEL_IN9) |
  ADC_SQR3_SQ4_N(ADC_CHANNEL_IN5) |
  ADC_SQR3_SQ5_N(ADC_CHANNEL_IN6) ,
};

void adcInit( void )
{

    /*
     * Initializes the ADC driver 1
      */
    adcStart( &ADCD1, NULL );

    adcStartConversion( &ADCD1,
                        &adcgrpcfg,
                        samples,
                        ADC_GRP1_BUF_DEPTH );
}


callbacks here

Code: Select all

/*
 * ADC error conversion callback.
 */
static void adcerrorcallback(ADCDriver *adcp, adcerror_t err) {

  (void)adcp;
  (void)err;
}

/*
 * ADC end conversion callback.
 */
void adcendcallback( ADCDriver *adcp, adcsample_t *buffer, size_t n )
{

    (void) n;
    (void)buffer;
    /* Note, only in the ADC_COMPLETE state because the ADC driver fires an
       intermediate callback when the buffer is half full.*/

    if( adcp->state == ADC_COMPLETE )
    {
    }
}


When run the adcendcallback is continously called with adcp->state == ADC_ACTIVE
Nothing else in the system runs.

Re: STM32F4xx ADC Driver not working

Posted: Tue Feb 14, 2017 4:58 pm
by Giovanni
Hi.

Are you testing with optimizations disabled? if not, breakpoints could be ignored. Callbacks work in the ADC demos, loot at that code.

Giovanni

Re: STM32F4xx ADC Driver not working

Posted: Tue Feb 14, 2017 5:08 pm
by RoccoMarco
Actually, what makes me confused is this:

Code: Select all

void adcInit( void )
{

    /*
     * Initializes the ADC driver 1
      */
    adcStart( &ADCD1, NULL );

    adcStartConversion( &ADCD1,
                        &adcgrpcfg,
                        samples,
                        ADC_GRP1_BUF_DEPTH );
}


The ADC already has a function named adcInit(). You should receive an error compiling your code.

Re: STM32F4xx ADC Driver not working

Posted: Tue Feb 14, 2017 5:16 pm
by Tabulous
Giovanni wrote:Hi.

Are you testing with optimizations disabled? if not, breakpoints could be ignored. Callbacks work in the ADC demos, loot at that code.

Giovanni


I never develop with any optimisation enabled, everything is off -O0 and LTO is off.

Re: STM32F4xx ADC Driver not working

Posted: Tue Feb 14, 2017 5:17 pm
by Tabulous
RoccoMarco wrote:Actually, what makes me confused is this:

Code: Select all

void adcInit( void )
{

    /*
     * Initializes the ADC driver 1
      */
    adcStart( &ADCD1, NULL );

    adcStartConversion( &ADCD1,
                        &adcgrpcfg,
                        samples,
                        ADC_GRP1_BUF_DEPTH );
}


The ADC already has a function named adcInit(). You should receive an error compiling your code.


i changed that to help people understand, in the real code it is psuInit();

Re: STM32F4xx ADC Driver not working

Posted: Tue Feb 14, 2017 5:29 pm
by Tabulous
Note the ADC works if i run in single conversion mode and trigger it every second by calling

Code: Select all

    adcStartConversion( &ADCD1,
                        &adcgrpcfg,
                        samples,
                        ADC_GRP1_BUF_DEPTH );


from a thread with one second sleep

Re: STM32F4xx ADC Driver not working

Posted: Tue Feb 14, 2017 6:04 pm
by Tabulous
Think i'm understanding the working of continuous mode wrong.

it runs all the time and you never get a ADC_COMPLETE state, this is where im going wrong :-)

Re: STM32F4xx ADC Driver not working

Posted: Wed Feb 15, 2017 2:34 pm
by Giovanni
I forgot that detail too...

Giovanni