2018-02-08 06:43 AM
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_out1Solved! Go to Solution.
2018-02-09 03:22 AM
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);
2018-02-08 07:54 AM
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.
2018-02-08 11:56 PM
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
2018-02-09 03:22 AM
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);