嘗試在 前進之前獲得一些簡單的DAC輸出。有一個萬用表輸出A2 ,但這似乎永遠不會從約1V6變化,無論我把什麼值 放入DAC2輸出功能。STM32 F446RE簡單的DAC輸出;我錯過了什麼?
#include "stm32f4xx.h"
#include "stm32f4xx_dac.h"
void io_config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* DMA1 & DMA2 clock and GPIOA & GPIOC clock enable */
RCC_AHB1PeriphClockCmd(/*RCC_AHB1Periph_DMA1 | RCC_AHB1Periph_DMA2 |*/
RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOB, ENABLE);
/* DAC Periph clock, TIM2 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC | RCC_APB1Periph_TIM2, ENABLE);
/* ADC1 Periph Clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
DAC_InitTypeDef dac_init_s;
int main(void)
{
unsigned int i, adcr;
i = adcr = 0;
io_config();
DAC_StructInit(&dac_init_s);
//dac_init_s.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
DAC_Init(DAC_Channel_2, &dac_init_s);
while(1) {
DAC_SetChannel2Data(DAC_Align_12b_R,500);
}
}