程序调试不出来,求教。

2019-07-14 21:09发布

我想做到把ADC采集的信号直接由DAC输出,在示波器上显示采集的信号,现在DA高输出管脚输出的一直是0电压,程序编译没有问题,求教大家帮忙,谢谢!#include<STM32f10x_lib.h>
#include<stdio.h>
void RCC_Configuration(void);
void GPIO_Configuration(void);
void USART_Configuration(void);
void ADC_Configuration(void);
void DAC_Configuration(void);
void SysTick_Configuration(void);
int main(void)
{
   float VolValue = 0.00;
        u32 ticks=0;
        float dac=0;                                       
   RCC_Configuration();
   GPIO_Configuration();
   USART_Configuration();
   ADC_Configuration();
        DAC_Configuration();
        SysTick_Configuration();
   printf(" The AD_value is:-------------------------- ");
while(1)
   {
          if(ticks++ >=2000000)
          {
          ticks=0;
     VolValue = 2.56 * ADC_GetConversionValue(ADC1) / 0X0FFF;
          dac=VolValue;
          DAC_SetChannel1Data(DAC_Align_12b_R,dac);
          printf( " The current VolValue1 = %.4fV ", VolValue);
          printf( " The current dac1 = 0X%X", ADC_GetConversionValue(ADC1));       
        // printf( " dac1 = %.4fV ", DAC_SetChannel1Data);
         
                }
   }
}
void RCC_Configuration(void)
{
   ErrorStatus HSEStartUpStatus;
   RCC_DeInit();
   RCC_HSEConfig(RCC_HSE_ON);
   HSEStartUpStatus = RCC_WaitForHSEStartUp();
   if(HSEStartUpStatus == SUCCESS)
   {
      RCC_HCLKConfig(RCC_SYSCLK_Div1);
      RCC_PCLK2Config(RCC_HCLK_Div1);
      RCC_PCLK1Config(RCC_HCLK_Div2);
      FLASH_SetLatency(FLASH_Latency_2);
      FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
      RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
      RCC_PLLCmd(ENABLE);
      while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
      RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
      while(RCC_GetSYSCLKSource() != 0x08);
   }
   RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOC | RCC_APB2Periph_ADC1, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC , ENABLE);
}
void GPIO_Configuration(void)
{
   GPIO_InitTypeDef GPIO_InitStructure;
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
   GPIO_Init(GPIOA , &GPIO_InitStructure);
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
   GPIO_Init(GPIOA , &GPIO_InitStructure);
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
   GPIO_Init(GPIOC , &GPIO_InitStructure);
   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 ;
   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
   GPIO_Init(GPIOA , &GPIO_InitStructure);
}
void ADC_Configuration(void)
{
   ADC_InitTypeDef ADC_InitStructure;
   RCC_ADCCLKConfig(RCC_PCLK2_Div8);
   ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
   ADC_InitStructure.ADC_ScanConvMode = ENABLE;
   ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
   ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
   ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
   ADC_InitStructure.ADC_NbrOfChannel = 1;
   ADC_Init(ADC1, &ADC_InitStructure);
   ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 1, ADC_SampleTime_55Cycles5);
   ADC_Cmd(ADC1, ENABLE);
   ADC_ResetCalibration(ADC1);
   while(ADC_GetResetCalibrationStatus(ADC1));
   ADC_StartCalibration(ADC1);
   while(ADC_GetCalibrationStatus(ADC1));
   ADC_SoftwareStartConvCmd(ADC1, ENABLE);       
}
void USART_Configuration(void)
{
   USART_InitTypeDef USART_InitStructure;
   USART_InitStructure.USART_BaudRate =9600;
   USART_InitStructure.USART_WordLength = USART_WordLength_8b;
   USART_InitStructure.USART_StopBits = USART_StopBits_1;
   USART_InitStructure.USART_Parity = USART_Parity_No ;
   USART_InitStructure.USART_HardwareFlowControl =  USART_HardwareFlowControl_None;
   USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
   USART_Init(USART1 , &USART_InitStructure);
   USART_Cmd(USART1 , ENABLE);
}
void DAC_Configuration(void)
{
   DAC_InitTypeDef DAC_InitStructure;
   DAC_InitStructure.DAC_Trigger=DAC_Trigger_None;
   DAC_InitStructure.DAC_WaveGeneration=DAC_WaveGeneration_None;
   DAC_InitStructure.DAC_OutputBuffer=DAC_OutputBuffer_Enable;
   DAC_Init(DAC_Channel_1,&DAC_InitStructure);
   DAC_Cmd(DAC_Channel_1,ENABLE);
}

void SysTick_Configuration(void)
{
   SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
   SysTick_SetReload(9000);
   SysTick_CounterCmd(SysTick_Counter_Enable);
   SysTick_ITConfig(ENABLE);               
}
int fputc(int ch, FILE *f)
{
   USART_SendData(USART1, (u8) ch);
   while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
   return ch;
}


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。