小学生
最后登录1970-1-1
在线时间 小时
注册时间2016-5-25
|
按野火的零死角STM32-V2 DAC输出正玄波。定时器触发DAC转换,DAC数据靠DMA自动循环输入,示波器没反应,用的是STM32F103C8T6单片机。希望大神帮我看看有什么问题配置上
#include "stm32f10x.h"
#include "stm32f10x_dac.h"
#include "stm32f10x_dma.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_tim.h"
void DAC_Mode_Init(void);
void DAC_TIM_Config(void);
void DAC_Config(void);
void DAC_DMA_Config(void);
const uint16_t Sine12bit[32] = {
2448,2832,3186,3496,3751,3940,4057,4095,4057,3940,
3751,3496,3186,2832,2448,2048,1648,1264,910,600,345,
156,39,0,39,156,345,600,910,1264,1648,2048};
#define DAC_DHR12RD_Address 0x40007420//Ë«í¨μàdacíaéè′«êäμØÖ·
uint32_t DualSine12bit[32];
int main(void)
{
DAC_Mode_Init();
while (1);
}
void DAC_Mode_Init(void)
{
uint32_t Idx = 0;
for (Idx = 0; Idx < 32; Idx++)
{
DualSine12bit[Idx] = (Sine12bit[Idx] << 16) + (Sine12bit[Idx]);
}
DAC_Config();
DAC_TIM_Config();
DAC_DMA_Config();
/* */
}
void DAC_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DAC_InitTypeDef DAC_InitStructure;
/* ??GPIOA ?? */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
/* ??DAC ?? */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
/* DAC GPIO */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; //TIM2
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; //
DAC_InitStructure.DAC_OutputBuffer= DAC_OutputBuffer_Disable;//
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
DAC_Init(DAC_Channel_2, &DAC_InitStructure);
// PA4
DAC_Cmd(DAC_Channel_1, ENABLE);
// PA5
DAC_Cmd(DAC_Channel_2, ENABLE);
DAC_DMACmd(DAC_Channel_2, ENABLE);
}
void DAC_TIM_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* 72M */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* TIM2 */
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 19; //72Mhz ÏÂ20¸öÖüÆúò»′Î′¥·¢DMA
TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);
/* TIM2 */
TIM_Cmd(TIM2, ENABLE);
}
void DAC_DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
/* DMA2 */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
/* DMA2 */
DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12RD_Address; //
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&DualSine12bit ; // Äú′æêy¾YμØÖ·DualSine12bit
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; //
DMA_InitStructure.DMA_BufferSize = 32; //
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; //
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;//
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //
DMA_Init(DMA2_Channel4, &DMA_InitStructure);
/* DMA2-4 */
DMA_Cmd(DMA2_Channel4, ENABLE);
}
|
|