Arm STM32 F446RE简单数模转换器输出;我错过了什么?
尝试在之前获得一些简单的DAC输出 继续前进。将万用表连接到输出A2上 但这似乎永远不会改变从大约1V6的任何价值 我输入了DAC2输出函数Arm STM32 F446RE简单数模转换器输出;我错过了什么?,arm,stm32,dac,Arm,Stm32,Dac,尝试在之前获得一些简单的DAC输出 继续前进。将万用表连接到输出A2上 但这似乎永远不会改变从大约1V6的任何价值 我输入了DAC2输出函数 #include "stm32f4xx.h" #include "stm32f4xx_dac.h" void io_config(void) { GPIO_InitTypeDef GPIO_InitStructure; /* DMA1 & DMA2 clock and GPIOA & GP
#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);
}
}
我不使用HAL作为这样一个简单的外围设备 启用时钟,配置GPIO引脚 第一频道
DAC -> CR |= DAC_CR_EN1;
DAC -> DHR12R1 = 454 /* your value */
第二频道
DAC -> CR |= DAC_CR_EN2;
DAC -> DHR12R2 = 454 /* your value */
用于波形生成(使用TIM6和DAC通道1)
我不使用HAL作为这样一个简单的外围设备 启用时钟,配置GPIO引脚 第一频道
DAC -> CR |= DAC_CR_EN1;
DAC -> DHR12R1 = 454 /* your value */
第二频道
DAC -> CR |= DAC_CR_EN2;
DAC -> DHR12R2 = 454 /* your value */
用于波形生成(使用TIM6和DAC通道1)
好的,这很有效!STM32F446RE核子DAC输出简单示例 与定时器和/或DMA等无关。已解决 老天爷
#include "stm32f4xx.h"
#include "stm32f4xx_dac.h"
void io_config2 (void) {
// Enable clocks for port A and DAC
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* DAC channel 2 Configuration */
DAC_InitTypeDef DAC_InitStructure2;
DAC_InitStructure2.DAC_Trigger = DAC_Trigger_None;
DAC_InitStructure2.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure2.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
DAC_Init(DAC_Channel_2, &DAC_InitStructure2);
/* DAC channel 1 Configuration */
DAC_InitTypeDef DAC_InitStructure1;
DAC_InitStructure1.DAC_Trigger = DAC_Trigger_None;
DAC_InitStructure1.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure1.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
DAC_Init(DAC_Channel_1, &DAC_InitStructure1);
/* Enable DAC Channel 1 and 2 */
DAC_Cmd(DAC_Channel_2, ENABLE);
DAC_Cmd(DAC_Channel_1, ENABLE);
}
DAC_InitTypeDef dac_init_s;
int main(void)
{
unsigned int i, adcr, j, k;
i = adcr = j = k = 0;
io_config2 ();
//DAC_Cmd( DAC_Channel_2, ENABLE);
DAC_Cmd( DAC_Channel_1, ENABLE);
while(1) {
#define OVAL 4095
//DAC_Cmd( DAC_Channel_2, DISABLE);
//DAC_SetChannel2Data(DAC_Align_12b_R, OVAL );
DAC_SetChannel1Data(DAC_Align_12b_R, OVAL ); /* 1000/4096 * 3V3 == 0V8 */
//if ( OVAL != DAC_GetDataOutputValue (DAC_Channel_2)) {
j = DAC_GetDataOutputValue (DAC_Channel_1);
k = DAC_GetDataOutputValue (DAC_Channel_2);
//}
}
}
好的,这很有效!STM32F446RE核子DAC输出简单示例 与定时器和/或DMA等无关。已解决 老天爷
#include "stm32f4xx.h"
#include "stm32f4xx_dac.h"
void io_config2 (void) {
// Enable clocks for port A and DAC
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* DAC channel 2 Configuration */
DAC_InitTypeDef DAC_InitStructure2;
DAC_InitStructure2.DAC_Trigger = DAC_Trigger_None;
DAC_InitStructure2.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure2.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
DAC_Init(DAC_Channel_2, &DAC_InitStructure2);
/* DAC channel 1 Configuration */
DAC_InitTypeDef DAC_InitStructure1;
DAC_InitStructure1.DAC_Trigger = DAC_Trigger_None;
DAC_InitStructure1.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure1.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
DAC_Init(DAC_Channel_1, &DAC_InitStructure1);
/* Enable DAC Channel 1 and 2 */
DAC_Cmd(DAC_Channel_2, ENABLE);
DAC_Cmd(DAC_Channel_1, ENABLE);
}
DAC_InitTypeDef dac_init_s;
int main(void)
{
unsigned int i, adcr, j, k;
i = adcr = j = k = 0;
io_config2 ();
//DAC_Cmd( DAC_Channel_2, ENABLE);
DAC_Cmd( DAC_Channel_1, ENABLE);
while(1) {
#define OVAL 4095
//DAC_Cmd( DAC_Channel_2, DISABLE);
//DAC_SetChannel2Data(DAC_Align_12b_R, OVAL );
DAC_SetChannel1Data(DAC_Align_12b_R, OVAL ); /* 1000/4096 * 3V3 == 0V8 */
//if ( OVAL != DAC_GetDataOutputValue (DAC_Channel_2)) {
j = DAC_GetDataOutputValue (DAC_Channel_1);
k = DAC_GetDataOutputValue (DAC_Channel_2);
//}
}
}