DAC Conversion probel on STM32L1xx

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
geoffroy
Posts: 7
Joined: Fri Oct 30, 2015 3:28 pm

DAC Conversion probel on STM32L1xx

Post by geoffroy »

Hi everybody,

I have a problem for converting a simple digital value with the DAC driver :
- In async mode, callbacks (error and success) are never called.
- In sync mode, the program blocks at dacConvert( .. ) more precisely l.304 of dac.c in osalThreadSuspendS ( .. )

Here is a minimal code to reproduce the issue (sync mode) :

Code: Select all

#include "ch.h"
#include "hal.h"

static const dacsample_t dac_buffer[1] = {2047};
static const DACConfig dac1cfg1 = {
  init:         2047U,
  datamode:     DAC_DHRM_12BIT_RIGHT
};

static const DACConversionGroup dacgrpcfg1 = {
  num_channels: 2U,
  end_cb:       NULL,
  error_cb:     NULL,
};

int main(void) {

  halInit();
  chSysInit();
  palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG);
  dacStart(&DACD1, &dac1cfg1);
  msg_t t1 = dacConvert(&DACD1, &dacgrpcfg1, dac_buffer, 1);

  while (true) {
    chThdSleepMilliseconds(500);
  }
  return 0;
}


My mcuconf.h:

Code: Select all

#define STM32_DAC_DUAL_MODE                 FALSE
#define STM32_DAC_USE_DAC1_CH1              TRUE
#define STM32_DAC_USE_DAC1_CH2              TRUE
#define STM32_DAC_DAC1_CH1_IRQ_PRIORITY     10
#define STM32_DAC_DAC1_CH2_IRQ_PRIORITY     10
#define STM32_DAC_DAC1_CH1_DMA_PRIORITY     2
#define STM32_DAC_DAC1_CH2_DMA_PRIORITY     2


I was inspired by the DAC demo for STM32F4xx ( in master/testhal/STM32/STM32F4xx/DAC/ )

Thanks for any help

Geoffroy
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: DAC Conversion probel on STM32L1xx

Post by Giovanni »

Hi,

It looks like the ISR is not being called, weekend task.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: DAC Conversion probel on STM32L1xx

Post by Giovanni »

Hi,

I added a DAC demo for the STM32L-Discovery, the callbback is invoked. Could you give it a try? it is on the repository trunk.

Giovanni
geoffroy
Posts: 7
Joined: Fri Oct 30, 2015 3:28 pm

Re: DAC Conversion probel on STM32L1xx

Post by geoffroy »

Hi Giovanni,

Thanks for this quick reply.

Your code works great, but I get always the same issue with dacConvert( ... ) method.
In fact, I need to have a single analogic value to the output of PA4 (not a sine wave, or something else)
I think I don't need to use GTP timer for that, and dacConvert( .. ) seems to fit my needs .
Maybe I missing something in my code sample, but I don't know what ..

Geoffroy
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: DAC Conversion probel on STM32L1xx

Post by Giovanni »

I will look into it further.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: DAC Conversion probel on STM32L1xx

Post by Giovanni »

I had a moment of blackout...

adcConvert() only returns when the conversion is stopped using dacStopConversion() or dacStopConversionI(), the conversion is circular so it does not terminates by itself. You need to stop it from another thread or an ISR.

Giovanni
geoffroy
Posts: 7
Joined: Fri Oct 30, 2015 3:28 pm

Re: DAC Conversion probel on STM32L1xx

Post by geoffroy »

Ok thanks, I will do that :) .

Regards,

Geoffroy
Post Reply