STM32F4xx ADC Driver not working

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

STM32F4xx ADC Driver not working

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F4xx ADC Driver not working

Post 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
User avatar
RoccoMarco
Posts: 655
Joined: Wed Apr 24, 2013 4:11 pm
Has thanked: 83 times
Been thanked: 67 times

Re: STM32F4xx ADC Driver not working

Post 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.
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: STM32F4xx ADC Driver not working

Post 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.
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: STM32F4xx ADC Driver not working

Post 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();
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: STM32F4xx ADC Driver not working

Post 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
Tabulous
Posts: 518
Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times

Re: STM32F4xx ADC Driver not working

Post 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 :-)
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32F4xx ADC Driver not working

Post by Giovanni »

I forgot that detail too...

Giovanni
Post Reply