2013-10-17 04:54 PM
Hi all,
I have two questions about DAC configuration.1. The below cofiguration code works for two analog outputs. I can write my values to PA4 and PA5 by: DAC_SetChannel1Data(DAC_Align_12b_R, 0x0000); // PA4 DAC_SetChannel2Data(DAC_Align_12b_R, 0x0000); // PA5But I wonder which part of the code links PA4 pin with DAC_channel1 and PA5 with DAC_channel2 together respectively? void AnalogOutput_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; DAC_InitTypeDef DAC_InitStructure; /* GPIOA clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); /* DAC Periph clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE); /*------------------------ GPIO configuration ------------------------*/ /* Configure PA4 and PA5 as analog output */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); /* -------------------------- DAC_Channel2 Configuration --------------------*/ DAC_DeInit(); DAC_InitStructure.DAC_Trigger = DAC_Trigger_None; DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; /*DAC Channel2 Init */ DAC_Init(DAC_Channel_2, &DAC_InitStructure); /*Enable DAC Channel2 */ DAC_Cmd(DAC_Channel_2, ENABLE); /* -----------------------------DAC_Channel1 Configuration ------------------------*/ DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; /*DAC Channel1 Init */ DAC_Init(DAC_Channel_1, &DAC_InitStructure); /*Enable DAC Channel1*/ DAC_Cmd(DAC_Channel_1, ENABLE); /* set default analog output as zero */ DAC_SetChannel1Data(DAC_Align_12b_R, 0x0000); // PA4 DAC_SetChannel2Data(DAC_Align_12b_R, 0x0000); // PA5}2. If one DAC channel can only be used by one analog output, at most I can only have two analog outputs. (There are only 2 dac channels for stm32l-discovery) What can I do if I want to include more analog outputs? Thanks a lot.2013-10-17 05:05 PM
You have very little control, they are hard-wired analogue paths.
You'd use an external DAC, perhaps using the I2S interface, or SPI.2013-10-17 11:02 PM
I used TLV5618A to extend DAC of STM32.