Skip to main content
jean-claude
Associate III
July 26, 2009
Question

DAC Programmation

  • July 26, 2009
  • 2 replies
  • 741 views
Posted on July 26, 2009 at 14:30

DAC Programmation

    This topic has been closed for replies.

    2 replies

    16-32micros
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:18

    Hi,

    You can start using the DAC examples provided in the Firmware Library :

    http://www.st.com/stonline/products/support/micro/files/stm32f10x_stdperiph_lib.zip and then tailor to your application.

    Cheers,

    STOne-32.

    jean-claude
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:18

    Hello,

    For my firt application, I want to use DAC.

    My aim is to send a constant value on the pin DAC_OUT1 (pin 20) by using channel 1 of the DAC.

    I made this code :

    #include ''stm32f10x_lib.h''

    #include ''stm32f10x_conf.h''

    #include ''stm32f10x_map.h''

    #include ''stm32f10x_dac.h''

    int main(void){

    DAC_DeInit();

    DAC_InitTypeDef DAC_InitStructure;

    DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;

    DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;

    DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0;

    DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;

    DAC_Init(DAC_Channel_1, &DAC_InitStructure);

    DAC_Init(DAC_Channel_2, &DAC_InitStructure);

    DAC_Cmd(DAC_Channel_1, ENABLE);

    DAC_Cmd(DAC_Channel_2, ENABLE);

    DAC_DMACmd(DAC_Channel_1, DISABLE);

    DAC_DMACmd(DAC_Channel_2, DISABLE);

    DAC_SoftwareTriggerCmd(DAC_Channel_1, DISABLE);

    DAC_SoftwareTriggerCmd(DAC_Channel_2, DISABLE);

    DAC_DualSoftwareTriggerCmd(DISABLE);

    DAC_SetChannel1Data(DAC_Align_12b_L, 0x500);

    DAC_SetChannel2Data(DAC_Align_12b_L, 0x400);

    USART_SendData(USART1, DAC_GetDataOutputValue(DAC_Channel_1));

    USART_SendData(USART2, DAC_GetDataOutputValue(DAC_Channel_2));

    }

    Firstly, I have a questions,

    My code is good ? I use too much function or not ?

    Are the data will be send on the DAC_OUTPUT1 ? (Using usart is just for simulation on debug mode)

    Secondly, I have a problem,

    The USART DATA REGISTERs 1 and 2 indicate 0x1ff although we must have 0x500 for USART1 and 0x400 for USART2.

    (DAC data and USART data use the same type : u12)

    So if someone have an idea. I will be happy.

    Thanks,

    JC.