完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
回复本帖可获得 1 分积分奖励! 每人限 1 次 |
我想做到把ADC采集的信号直接由DAC输出,在示波器上显示采集的信号,现在DA高输出管脚输出的一直是0电压,程序编译没有问题,求教大家帮忙,谢谢!#include<STM32f10x_lib.h>
#include 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("rn The AD_value is:-------------------------- rn"); while(1) { if(ticks++ >=2000000) { ticks=0; VolValue = 2.56 * ADC_GetConversionValue(ADC1) / 0X0FFF; dac=VolValue; DAC_SetChannel1Data(DAC_Align_12b_R,dac); printf( "rnThe current VolValue1 = %.4fVrn", VolValue); printf( "rnThe current dac1 = 0X%X", ADC_GetConversionValue(ADC1)); // printf( "rn dac1 = %.4fVrn", 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; } |
|
相关推荐
4个回答
|
|
编译有问题你也下不进去
|
|
|
|
回帖奖励 +1 分积分
使用断点或者printf等方式调试啊,找问题,是AD部分还是DA部分,定位问题
|
|
|
|
回帖奖励 +1 分积分 |
|
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1252 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1184 浏览 3 评论
2263 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
1351 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1774 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-28 05:57 , Processed in 0.676527 second(s), Total 81, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号