Skip to main content
Davy Straetemans
Associate
February 8, 2018
Solved

STM8AL3136: How to get DAC1 on PB4

  • February 8, 2018
  • 2 replies
  • 2600 views
Posted on February 08, 2018 at 15:43

I'm using the example code from STM8L15x-16x-05x-AL31-L_StdPeriph_Lib as a starting point.

I'm able to get GPIO and I2C working but the configuration to get the DAC1 on pin PB4 not working.

I have the following configuration:

SYSCFG_RIIOSwitchConfig(RI_IOSwitch_15, ENABLE); //get DAC1 on PB4 pin

CLK_PeripheralClockConfig(CLK_Peripheral_DAC, ENABLE);

DAC_DeInit();

DAC_Init(DAC_Channel_1, DAC_Trigger_None, DAC_OutputBuffer_Enable);

DAC_SetChannel1Data(DAC_Align_12b_R, 2000);

but the output on PB4 stay's zero.

Also tried adding a check to be sure the DAC value is set correctly with:

while(4000 != DAC_GetDataOutputValue(DAC_Channel_1));

and the loop is just exited.

The problem must be in the IO switch configuration, but i have no clue what it could be.

Any idea's?

#io-pins-matrix-switch-peripheral #dac_out1
This topic has been closed for replies.
Best answer by Davy Straetemans
Posted on February 09, 2018 at 12:22

I have been able to get the DAC output on pin PB4.

The Peripheral clock for COMP has to be enabled before doing the IO switch.

This is the code that works for me:

CLK_PeripheralClockConfig(CLK_Peripheral_COMP, ENABLE);

SYSCFG_RIDeInit();

SYSCFG_RIIOSwitchConfig(RI_IOSwitch_15, ENABLE);

/* ADC clock Enable*/

CLK_PeripheralClockConfig(CLK_Peripheral_DAC, ENABLE);

DAC_DeInit();

/* Init DAC, no trigger, disable output buffer */

DAC_Init(DAC_Channel_1, DAC_Trigger_None, DAC_OutputBuffer_Enable);

DAC_Cmd(DAC_Channel_1, ENABLE);

DAC_SetChannel1Data(DAC_Align_12b_R, 4000);

while(4000 != DAC_GetDataOutputValue(DAC_Channel_1));

After this the output can be changed by using:

DAC_SetChannel1Data(DAC_Align_12b_R, 2000);

 

2 replies

Simon V.
ST Employee
February 8, 2018
Posted on February 08, 2018 at 16:54

Hello,

Please checked the remap of the pin in the RM0031 section 11.2.6 DAC routing...

Let me know if you are facing troubles,

Regards,

Simon

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Davy Straetemans
Associate
February 9, 2018
Posted on February 09, 2018 at 07:56

I did, therefore i used the SYSCFG_RIIOSwitchConfig().

This will write CH15E in the RI_IOSR3 register which should connect the DAC1 output to pin PB4

Davy Straetemans
Davy StraetemansAuthorBest answer
Associate
February 9, 2018
Posted on February 09, 2018 at 12:22

I have been able to get the DAC output on pin PB4.

The Peripheral clock for COMP has to be enabled before doing the IO switch.

This is the code that works for me:

CLK_PeripheralClockConfig(CLK_Peripheral_COMP, ENABLE);

SYSCFG_RIDeInit();

SYSCFG_RIIOSwitchConfig(RI_IOSwitch_15, ENABLE);

/* ADC clock Enable*/

CLK_PeripheralClockConfig(CLK_Peripheral_DAC, ENABLE);

DAC_DeInit();

/* Init DAC, no trigger, disable output buffer */

DAC_Init(DAC_Channel_1, DAC_Trigger_None, DAC_OutputBuffer_Enable);

DAC_Cmd(DAC_Channel_1, ENABLE);

DAC_SetChannel1Data(DAC_Align_12b_R, 4000);

while(4000 != DAC_GetDataOutputValue(DAC_Channel_1));

After this the output can be changed by using:

DAC_SetChannel1Data(DAC_Align_12b_R, 2000);