cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with changing DAC Register via ST-Link

John Lowen
Associate II
Posted on July 29, 2017 at 00:27

I am having trouble changing any DAC registers using the STLINK debugger. The processor is stopped and the DAC is configured via Cube to be DAC Out 1 with output buffer enabled and no triggering. I let the code run through the Cube generated initialization code and stop at a breakpoint. Any attempt to change a register value or bit is not successful, i.e. the value does not change.

Has anyone encountered this?

#dac_out1
8 REPLIES 8
Posted on July 29, 2017 at 01:18

Hello !!!

You did not mention anything about your hardware..

Anyway , in general, the initialization is not enough by itself.

try to call at your main function..

// is to set the value

HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_8B_R, 100);

// and to start the conversion

HAL_DAC_Start(&hdac, DAC_CHANNEL_1);

change parameters accordingly

Rgrds

Posted on July 29, 2017 at 01:56

It shouldn't matter when it comes to changing registers by the st link

debugger. I can change other peripheral registers regardless of how the

code set them up. I just can't change the Dac registers. I am using an

stm32F764.

On Jul 28, 2017 7:19 PM, 'Vangelis Fortounas' <

Posted on July 29, 2017 at 02:47

Hello John!

probably you mean stm32f765

Check your VDDA  VREF and VSSA pins if have the proper voltages.

By your st link check at  the following register the DACEN: bit

RCC APB1 peripheral clock enable register (RCC_APB1ENR).

If is disabled, DAC is not properly initialised  (and ofcourse imposible to read or write to it)

If is enabled,  and the DAC is working normal (not by giving commands from ST LINK )  the  problem is somewhere in your IDE.

Regards

S.Ma
Principal
Posted on July 29, 2017 at 19:57

If the registers are stuck, it could be a missing clock enable. Make sure the supply to analog is present and no dma nor automatic waveform generation kicked in. Check all registers values vs reference manual to make sure its configuration is good enough. Also look at gpio rcc and sys registers.

Posted on July 31, 2017 at 17:23

Hi Vangelis,

Thanks for the help. It turns out that the DACEN bit in RCC_APB1ENR was not set. I was looking in Cube for a way to set this but did not see one. Is there a HAL call that will do this or do you have to simply do it via code in user sections? I was successful in doing it manually but would like to know if there is a Cube or HAL option to set this.

Posted on July 31, 2017 at 19:17

Hi John!

Normaly, there are produced 2 functions from CUBE.

static void MX_DAC_Init(void)

and

void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)

The second function called from inside the first.

By yourself you can use this macro to enable the clock for DAC

__HAL_RCC_DAC_CLK_ENABLE();

Posted on July 31, 2017 at 19:31

I reviewed both functions and did not see the DAC being enabled. I did

notice that the HAL_DAC_MspInit(DAC_HandleTypeDef* hdac) function was a

weak function that I could override. Should I do it via override? I would

think that there would be an easy way to turn on the DAC. ConfigChannel

didn't have anything relevant in it either. The MACRO is fine but I'd

rather use Cube if possible. Below is my MX_DAC_Init():

/* DAC init function */

static void MX_DAC_Init(void)

{

DAC_ChannelConfTypeDef sConfig;

/**DAC Initialization

*/

hdac.Instance = DAC;

if (HAL_DAC_Init(&hdac) != HAL_OK)

{

Error_Handler();

}

/**DAC channel OUT1 config

*/

sConfig.DAC_Trigger = DAC_TRIGGER_NONE;

sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;

if (HAL_DAC_ConfigChannel(&hdac, &sConfig, DAC_CHANNEL_1) != HAL_OK)

{

Error_Handler();

}

}

​​John Lowen

Senior Engineer, Product Care

2415 Cascade Pointe Boulevard ​Charlotte NC 28208

SealedAir.com <http://www.sealedair.com/>

​C: +704 503 8795

john.lowen@sealedair.com <%E2%80%8Bnik.crosina@sealedair.com>

On Mon, Jul 31, 2017 at 1:18 PM, Vangelis Fortounas <

Posted on July 31, 2017 at 19:52

HAL_DAC_MspInit(DAC_HandleTypeDef* hdac) is produced by CUBE and contains the clock enabling macro. Also, contains GPIO initialisations for DAC.

I Use the last version of CUBEMX and produces this function

Please compile the attached .IOC file

void HAL_DAC_MspInit(DAC_HandleTypeDef* hdac)

{

GPIO_InitTypeDef GPIO_InitStruct;

if(hdac->Instance==DAC)

{

/* USER CODE BEGIN DAC_MspInit 0 */

/* USER CODE END DAC_MspInit 0 */

/* Peripheral clock enable */

__HAL_RCC_DAC_CLK_ENABLE();

/**DAC GPIO Configuration

PA4 ------> DAC_OUT1

*/

GPIO_InitStruct.Pin = GPIO_PIN_4;

GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;

GPIO_InitStruct.Pull = GPIO_NOPULL;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/* USER CODE BEGIN DAC_MspInit 1 */

/* USER CODE END DAC_MspInit 1 */

}

}

________________

Attachments :

764dac.ioc.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HyXF&d=%2Fa%2F0X0000000b9C%2Fmd9.4kFr4tTHpPkkRIxaTzktAZ14texzCmAloOCQQ70&asPdf=false