cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo STM32F334R8 DAC

heap
Associate II
Posted on October 23, 2014 at 14:05

Hello community,

Actually I evaluating DAC on NucF334R8. 

DAC1

_

Channel1

 seems to work 

but I am not able getting 

DAC2

_

Cannel1

 (Pin 

PA6

) to work.

 I created the C Framework with STMCubeMX 4.4.0 - both channels with equal settings.

[snip main.c]

...

  /* USER CODE BEGIN 2 */

HAL_TIM_Base_Start(&htim6);

HAL

_

DAC

_Start(&

hdac1

, DAC1_CHANNEL_1);

HAL

_TIM_Base_Start(&

htim7

);

HAL

_

DAC

_Start(&

hdac2

DAC1

_CHANNEL_1);

....

/* 

TIM6

 

init

 function */

void 

MX

_

TIM6

_

Init

(void)

{

  TIM_

MasterConfigTypeDef

 sMasterConfig;

  htim6.Instance = 

TIM6

;

  htim6.

Init

.

Prescaler

 = 0;

htim6.

Init

.

ClockDivision

 = 0;

  htim6.

Init

.

CounterMode

 = TIM_

COUNTERMODE

_UP;

  htim6.

Init

.Period = 

0x1

;

  

HAL

_TIM_Base_

Init

(&htim6);

  sMasterConfig.

MasterOutputTrigger

 = TIM_

TRGO

_UPDATE;

  sMasterConfig.

MasterSlaveMode

 = TIM_

MASTERSLAVEMODE

_DISABLE;

  

HAL

_

TIMEx

_

MasterConfigSynchronization

(&htim6, &sMasterConfig);

}

/* 

TIM7

 

init

 function */

void 

MX

_

TIM7

_

Init

(void)

{

  TIM_

MasterConfigTypeDef

 sMasterConfig;

  

htim7

.Instance = 

TIM7

;

  

htim7

.

Init

.Prescore = 0;

  

htim7

.

Init

.

CounterMode

 = TIM_

COUNTERMODE

_UP;

htim7

.

Init

.

ClockDivision

 = 0;

  

htim7

.

Init

.Period = 

0x1

;

  

HAL

_TIM_Base_

Init

(&

htim7

);

  sMasterConfig.

MasterOutputTrigger

 = TIM_

TRGO

_UPDATE;

  sMasterConfig.

MasterSlaveMode

 = TIM_

MASTERSLAVEMODE

_DISABLE;

  

HAL

_

TIMEx

_MasterConfigSynchronization(&

htim7

, &sMasterConfig);

... 

[snap]

DAC1

 - yellow; 

DAC2

 - blue

0690X00000605OxQAI.png

Now I am using Keil Lite IDE but with mbed I got the same results....

Does anybody have an idea what is wrong ?

regards
13 REPLIES 13
Posted on October 23, 2014 at 14:33

Does anybody have an idea what is wrong ?

Probably not both DAC1_CHANNEL_1

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
heap
Associate II
Posted on October 23, 2014 at 16:11

Hello

 you are right - I changed it to 

DAC2

_CHANNEL_1  but nothing varried...

 

frankmeyer9
Associate II
Posted on October 23, 2014 at 16:27

 you are right - I changed it to 

DAC2

_CHANNEL_1  but nothing varried...

 

Perhaps the DAC initialisation code, which you did not present here, contains a similiar copy&paste bug ?

heap
Associate II
Posted on October 23, 2014 at 17:11

The init code was not pate&copy - was created with STMCubeMX

but here it is:

/* DAC1 init function */

void MX_DAC1_Init(void)

{

  DAC_ChannelConfTypeDef sConfig;

    /**DAC Initialization 

    */

  hdac1.Instance = DAC1;

  HAL_DAC_Init(&hdac1);

    /**DAC channel OUT1 config 

    */

  sConfig.DAC_Trigger = DAC_TRIGGER_T6_TRGO;

  sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE;

  HAL_DAC_ConfigChannel(&hdac1, &sConfig, DAC_CHANNEL_1);

    /**Configure Triangle wave generation on DAC OUT1 

    */

  HAL_DACEx_TriangleWaveGenerate(&hdac1, DAC_CHANNEL_1, DAC_TRIANGLEAMPLITUDE_2047);

}

/* DAC2 init function */

void MX_DAC2_Init(void)

{

  DAC_ChannelConfTypeDef sConfig;

    /**DAC Initialization 

    */

  hdac2.Instance = DAC2;

  HAL_DAC_Init(&hdac2);

    /**DAC channel OUT1 config 

    */

  sConfig.DAC_Trigger = DAC_TRIGGER_T7_TRGO;

  sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_DISABLE;

  HAL_DAC_ConfigChannel(&hdac2, &sConfig, DAC_CHANNEL_1);

    /**Configure Triangle wave generation on DAC OUT1 

    */

  HAL_DACEx_TriangleWaveGenerate(&hdac2, DAC_CHANNEL_1, DAC_TRIANGLEAMPLITUDE_2047);

}

/* TIM6 init function */

void MX_TIM6_Init(void)

{

  TIM_MasterConfigTypeDef sMasterConfig;

  htim6.Instance = TIM6;

  htim6.Init.Prescaler = 0;

htim6.Init.ClockDivision = 0;

  htim6.Init.CounterMode = TIM_COUNTERMODE_UP;

  htim6.Init.Period = 0x1;

  HAL_TIM_Base_Init(&htim6);

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;

  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

  HAL_TIMEx_MasterConfigSynchronization(&htim6, &sMasterConfig);

}

/* TIM7 init function */

void MX_TIM7_Init(void)

{

  TIM_MasterConfigTypeDef sMasterConfig;

  htim7.Instance = TIM7;

  htim7.Init.Prescaler = 0;

  htim7.Init.CounterMode = TIM_COUNTERMODE_UP;

htim7.Init.ClockDivision = 0;

  htim7.Init.Period = 0x1;

  HAL_TIM_Base_Init(&htim7);

  sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;

  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

  HAL_TIMEx_MasterConfigSynchronization(&htim7, &sMasterConfig);

}

frankmeyer9
Associate II
Posted on October 23, 2014 at 21:29

Tried to debug and compare register settings (DAC1 vs. DAC2) ?

Some external hardware on the DAC2 output pin ? The DAC is of high impedance, so very sensitive.

Sorry, but I don't touch Cube code, just too buggy for me.

I think it is no coincidence  that forum participation by ST staff rose about 1000% after introduction of the CubeMx software.

heap
Associate II
Posted on October 24, 2014 at 04:30

Hello - no load on PA_4 and PA_6 - only oscilloscope is connected.

I compared DAC1 versus DAC2 register:

DAC1_CR@0x40007400 is right (0xB85) initialized.

DAC2_CR@0x40009800 is 0x17. SO WAVE1 bits and MAMP1 Bits are all '0'.

And I am not able to set them manually in debug session. 

In contrast DAC1_CR register bits could set manually in debug session.

I am a newbie in embedded programming - sorry for my unhandy.

frankmeyer9
Associate II
Posted on October 24, 2014 at 08:50

I am a newbie in embedded programming - sorry for my unhandy.

 

Nevermind, that's what this fora are for.

I compared DAC1 versus DAC2 register:

 

DAC1_CR@0x40007400 is right (0xB85) initialized.

 

DAC2_CR@0x40009800 is 0x17. SO WAVE1 bits and MAMP1 Bits are all '0'.

 

 

And I am not able to set them manually in debug session. 

 

In contrast DAC1_CR register bits could set manually in debug session.

 

In contrast to stm32f40x devices, the f334 has separate clock enable bits for the two DAC channels.

So can you check RCC_APB1ENR, Bits 26 and 29 when your code tries to configure the DACs ?

According to your description, I would expect bit 26 to be zero, probably representing another CubeMX bug.

BTW, it's always a good idea to download the reference manual and datasheet of the MCU you are working with, if you did not already.

heap
Associate II
Posted on October 24, 2014 at 10:04

Hello

So can you check RCC_APB1ENR, Bits 26 and 29 when your code tries to configure the DACs ?

 

According to your description, I would expect bit 26 to be zero, probably representing another CubeMX bug.

Bit 26 and Bit 29 of APB1ENR Register are 1

BTW, it's always a good idea to download the reference manual and datasheet of the MCU you are working with, if you did not already.

Yes I did but I found nothing that's would fit to the problem.

>DAC2_CR@0x40009800 is 0x17. SO WAVE1 bits and MAMP1 Bits are all '0'.

 

>And I am not able to set them manually in debug session. 

It seems that the WAVE1 bits and MAMP1 Bits of the DAC2_CR register are reseted to zero after I set them manually. No idea why...

frankmeyer9
Associate II
Posted on October 24, 2014 at 10:24

It seems that the WAVE1 bits and MAMP1 Bits of the DAC2_CR register are reseted to zero after I set them manually. No idea why...

 

That is the usual behavior if the clock of that peripheral had not been enabled previously.

But as you reported, both enable bits in APB1ENR are set.

I had only used the DAC of F05x, F10x and F4xx, so not sure what else is different.

I would have recommended to try a StandardPeripheralLibrary example (not CubeMX) but that seems not to exist for this MCU variant.

Thank you ST, so much for the StdPeriphLib support ...