Page 2 of 2

Re: DAC error for STM32F4 discovery

Posted: Tue Jan 20, 2015 8:38 pm
by deeznutz
Ok, I will check that tomorow... Thanks!

Nils

Re: DAC error for STM32F4 discovery

Posted: Thu Jan 22, 2015 7:14 pm
by mobyfab
Hey,

I will make some examples, they will be in the repo with the drivers.

Re: DAC error for STM32F4 discovery

Posted: Tue Apr 14, 2015 4:19 am
by MarkusS
Fabien,

I think I found two small errors in you DAC driver (I used the one from https://github.com/ChibiOS/ChibiOS-Driv ... hibiOS-2.6): I was trying to use dacConvert with channel 2 on a custom STM32F4 board, but at first I only could set channel 1, channel 2 stayed at 0 V.

In dac_lld_single_convert, you do some pointer arithmetic for channel 2:

dataoffset = &dacp->dac->DHR12R2 - &dacp->dac->DHR12R1;

and then later

data = ((dacsample_t*)&dacp->dac->DHR12R1) + dataoffset;

What you want is data == &dacp->dac->DHR12R1 for channel 1 and data == dacp->dac->DHR12R2 for channel 2, but since dacsample_t is of type uint16_t, you don't get this (in fact, data is pointing in between DHR12R2 and DHR12R1... for channel 2)
If you change the definition of dacsample_t in dac_lld.h to uint32_t, setting channel 2 works for me.

But there is another problem, setting channel 2 clears the DAC output of channel 1, reason:

you do a
dacp->dac->CR &= ~(STM32_DAC_CR_MASK << regshift);
dacp->dac->CR = ((STM32_DAC_CR_EN | STM32_DAC_CR_TSEL_SOFT | dacp->config->cr_flags) << regshift);

but I think the last line should be:
dacp->dac->CR |= ((STM32_DAC_CR_EN | STM32_DAC_CR_TSEL_SOFT | dacp->config->cr_flags) << regshift);

With those two changes I can call
dacConvert(&DACD1, value1);
dacConvert(&DACD2, value2);

and both DAC outputs are at the expected values...

I did not try the 3.0 version of your driver, but from a quick look it seems that those items are the same, so I would assume that the 3.0 DAC driver has the seem issues.

Thanks a lot for your nice driver,

Markus

Re: DAC error for STM32F4 discovery

Posted: Tue Apr 14, 2015 9:11 pm
by mobyfab
Thanks for the feedback, I will have a look :)

The driver in 3.0 has some fixes, also the API is different.