2014-10-23 05:05 AM
Hello community,
Actually I evaluating DAC on NucF334R8.DAC1
_Channel1
seems to work but I am not able gettingDAC2
_Cannel1
(PinPA6
) 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 */voidMX
_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 */voidMX
_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
- blueNow I am using Keil Lite IDE but with mbed I got the same results....Does anybody have an idea what is wrong ?regards2014-10-23 05:33 AM
Does anybody have an idea what is wrong ?
Probably not both DAC1_CHANNEL_12014-10-23 07:11 AM
Hello
you are right - I changed it toDAC2
_CHANNEL_1 but nothing varried...
2014-10-23 07:27 AM
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 ?
2014-10-23 08:11 AM
The init code was not pate© - 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);}2014-10-23 12:29 PM
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.2014-10-23 07:30 PM
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.2014-10-23 11:50 PM
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.
2014-10-24 01:04 AM
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 1BTW, 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...
2014-10-24 01:24 AM
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 ...