现在在做一个adc_dma的小任务。但是捣鼓了很久也做不出来,其中还有些问题自己无法解决,只好上来寻求大佬们帮忙。
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "key.h"
#include "beep.h"
#include "stdio.h"
#include "exit.h"
#include "iwdg.h"
#include "timer.h"
#include "pwm.h"
#include "dac.h"
#include "adc.h"
#include "dma.h"
#define ADC1_DR_ADDRESS ((uint32_t)0x4001204C)
int main(void)
{
double adcx;
Stm32_Clock_Init(336,8,2,7);//设置时钟,168Mhz
delay_init(168); //延时初始化
KEY_Init();
BEEP_Init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
LED_Init();
uart_init(84,115200); //串口初始化为115200
TIMER_Init(4,8399);
MYDMA_Init(DMA2_Stream0,DMA_Channel_0,(u32)ADC1_DR_ADDRESS,(u32)SENDBUFFER,128);//DMA2,STEAM7,CH4,外设为串口1,存储器为SendBuff,长度为:SEND_BUF_SIZE.
ADC_GPIO_INIT();//名字可能不规范,但是里面是adc 的初始化
DAC_GPIO_Init();//名字可能不规范,但是里面是adc 的初始化
DAC_SetChannel1Data(DAC_Align_12b_R,1000);
while(1)
{
adcx=DAC_GetDataOutputValue(DAC_Channel_1);
adcx=adcx*(3.3/4096);
printf("%f",adcx);
AverageValue();
}
当我注释ADC_GPIO_INIT()的时候,printf("%f",adcx);可以正常的输出数据
,但是一旦我使用ADC_GPIO_INIT()的时候,循环就会卡死,在串口上看也没有任何的输出
下面是 ADC_GPIO_INIT()内容
void ADC_GPIO_INIT(void)
{
ADC_CommonInitTypeDef ADC_CommonInitStruct;
GPIO_InitTypeDef GPIO_InitStruct;
ADC_InitTypeDef ADC_InitStruct ;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,ENABLE);
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AN;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_5;
GPIO_InitStruct.GPIO_PuPd=GPIO_PuPd_NOPULL;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_100MHz;
GPIO_Init(GPIOA,&GPIO_InitStruct);
ADC_DeInit();
ADC_CommonInitStruct.ADC_DMAAccessMode=ADC_DMAAccessMode_Disabled ;
ADC_CommonInitStruct.ADC_Mode=ADC_Mode_Independent;
ADC_CommonInitStruct.ADC_Prescaler=ADC_Prescaler_Div4;
ADC_CommonInitStruct.ADC_TwoSamplingDelay=ADC_TwoSamplingDelay_5Cycles ;
ADC_CommonInit(&ADC_CommonInitStruct);
ADC_InitStruct.ADC_ContinuousConvMode=ENABLE;
ADC_InitStruct.ADC_DataAlign=ADC_DataAlign_Right;
ADC_InitStruct.ADC_ExternalTrigConvEdge=ADC_ExternalTrigConvEdge_None;
ADC_InitStruct.ADC_NbrOfConversion=1;
ADC_InitStruct.ADC_Resolution=ADC_Resolution_12b ;
ADC_InitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
ADC_InitStruct.ADC_ScanConvMode=DISABLE;
ADC_Init(ADC1,&ADC_InitStruct);
ADC_RegularChannelConfig(ADC1,ADC_Channel_5,1,ADC_SampleTime_480Cycles);
ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
ADC_DMACmd(ADC1, ENABLE);
ADC_Cmd(ADC1,ENABLE);
ADC_SoftwareStartConv(ADC1);
}
一周热门 更多>