本帖最后由 进无止境6A 于 2019-1-3 16:38 编辑
用的是STM32F767,今天感觉ADC不对就去下载了@正点原子的的二十五章ADC实验、二十六章内部温度传感器、二十七章的DAC实验,
发现ADC采集到的电压总是在0.3v左右,感觉ADC坏了,我有换了ADC2.ADC3,结果是一样的,
而内部温度传感器ADC是正常的,采集到的温度是52度
那问题来了,到底是哪里坏了?
下面是我实物拍摄图,帮忙看下有没有接错了还是什么问题@正点原子,@老帖们,@大佬
下面是源码:
#include "adc.h"
#include "delay.h"
//////////////////////////////////////////////////////////////////////////////////
//±¾3ìDòÖ»1©Ñ§Ï°ê1óã¬Î′¾-×÷ÕßDí¿é£¬2»μÃóÃóúÆäËüèÎoÎóÃí¾
//ALIENTEK STM32F7¿a·¢°å
//ADCÇy¶ˉ′úÂë
//ÕyμãÔ-×ó@ALIENTEK
//¼¼êõÂÛì3:
www.openedv.com
//′′½¨èÕÆú:2015/12/26
//°æ±¾£oV1.0
//°æè¨ËùóD£¬μá°æ±Ø¾¿¡£
//Copyright(C) 1ãÖYêDDÇòíμç×ó¿Æ¼¼óDÏT1«Ë¾ 2014-2024
//All rights reserved
//////////////////////////////////////////////////////////////////////////////////
ADC_HandleTypeDef ADC1_Handler;//ADC¾ä±ú
//3õê¼»ˉADC
//ch: ADC_channels
//í¨μàÖμ 0~16è¡Öμ·¶Î§Îa£oADC_CHANNEL_0~ADC_CHANNEL_16
void MY_ADC_Init(void)
{
ADC1_Handler.Instance=ADC1;
ADC1_Handler.Init.ClockPrescaler=ADC_CLOCK_SYNC_PCLK_DIV4; //4·ÖÆ죬ADCCLK=PCLK2/4=108/4=27MHZ
ADC1_Handler.Init.Resolution=ADC_RESOLUTION_12B; //12λÄ£ê½
ADC1_Handler.Init.DataAlign=ADC_DATAALIGN_RIGHT; //óò¶ÔÆë
ADC1_Handler.Init.ScanConvMode=DISABLE; //·Çé¨ÃèÄ£ê½
ADC1_Handler.Init.EOCSelection=DISABLE; //1رÕEOCÖD¶Ï
ADC1_Handler.Init.ContinuousConvMode=DISABLE; //1رÕá¬Dø×a»»
ADC1_Handler.Init.NbrOfConversion=1; //1¸ö×a»»Ôú1æÔòDòáDÖD ò2¾íêÇÖ»×a»»1æÔòDòáD1
ADC1_Handler.Init.DiscontinuousConvMode=DISABLE; //½ûÖ12»á¬Dø2éÑùÄ£ê½
ADC1_Handler.Init.NbrOfDiscConversion=0; //2»á¬Dø2éÑùí¨μàêyÎa0
ADC1_Handler.Init.ExternalTrigConv=ADC_SOFTWARE_START; //èí¼t′¥·¢
ADC1_Handler.Init.ExternalTrigConvEdge=ADC_EXTERNALTRIGCONVEDGE_NONE;//ê1óÃèí¼t′¥·¢
ADC1_Handler.Init.DMAContinuousRequests=DISABLE; //1رÕDMAÇëÇó
HAL_ADC_Init(&ADC1_Handler); //3õê¼»ˉ
}
//ADCμ×2ãÇy¶ˉ£¬òy½ÅÅäÖã¬ê±Öóê1Äü
//′Ëoˉêy»á±»HAL_ADC_Init()μ÷óÃ
//hadc:ADC¾ä±ú
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
GPIO_InitTypeDef GPIO_Initure;
__HAL_RCC_ADC1_CLK_ENABLE(); //ê1ÄüADC1ê±Öó
__HAL_RCC_GPIOA_CLK_ENABLE(); //¿aÆôGPIOAê±Öó
GPIO_Initure.Pin=GPIO_PIN_5; //PA5
GPIO_Initure.Mode=GPIO_MODE_ANALOG; //Ä£Äa
GPIO_Initure.Pull=GPIO_NOPULL; //2»′øéÏÏÂà-
HAL_GPIO_Init(GPIOA,&GPIO_Initure);
}
//»ñμÃADCÖμ
//ch: í¨μàÖμ 0~16£¬è¡Öμ·¶Î§Îa£oADC_CHANNEL_0~ADC_CHANNEL_16
//·μ»ØÖμ:×a»»½á1û
u16 Get_Adc(u32 ch)
{
ADC_ChannelConfTypeDef ADC1_ChanConf;
ADC1_ChanConf.Channel=ch; //í¨μà
ADC1_ChanConf.Rank=1; //1¸öDòáD
ADC1_ChanConf.SamplingTime=ADC_SAMPLETIME_480CYCLES; //2éÑùê±¼ä
ADC1_ChanConf.Offset=0;
HAL_ADC_ConfigChannel(&ADC1_Handler,&ADC1_ChanConf); //í¨μàÅäÖÃ
HAL_ADC_Start(&ADC1_Handler); //¿aÆôADC
HAL_ADC_PollForConversion(&ADC1_Handler,10); //ÂÖÑˉ×a»»
return (u16)HAL_ADC_GetValue(&ADC1_Handler); //·μ»Ø×î½üò»′ÎADC11æÔò×éμÄ×a»»½á1û
}
//»ñè¡Ö¸¶¨í¨μàμÄ×a»»Ö죬è¡times′Î,è»oóƽ¾ù
//times:»ñè¡′Îêy
//·μ»ØÖμ:í¨μàchμÄtimes′Î×a»»½á1ûƽ¾ùÖμ
u16 Get_Adc_Average(u32 ch,u8 times)
{
u32 temp_val=0;
u8 t;
for(t=0;t<times;t++)
{
temp_val+=Get_Adc(ch);
delay_ms(5);
}
return temp_val/times;
}
#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "key.h"
#include "lcd.h"
#include "sdram.h"
#include "adc.h"
/************************************************
ALIENTEK °¢2¨ÂTSTM32F7¿a·¢°å êμÑé20
ADCÄ£êy×a»»êμÑé-HAL¿aoˉêy°æ
¼¼êõÖ§3Ö£o
www.openedv.com
ìÔ±|μêÆì£o
http://eboard.taobao.com
1Øע΢DÅ1«Öúƽì¨Î¢DÅoÅ£o"ÕyμãÔ-×ó"£¬Ãa·Ñ»ñè¡STM32×êáÏ¡£
1ãÖYêDDÇòíμç×ó¿Æ¼¼óDÏT1«Ë¾
×÷ÕߣoÕyμãÔ-×ó @ALIENTEK
************************************************/
int main(void)
{
u16 adcx;
float temp;
Cache_Enable(); //′ò¿aL1-Cache
HAL_Init(); //3õê¼»ˉHAL¿a
Stm32_Clock_Init(432,25,2,9); //éèÖÃê±Öó,216Mhz
delay_init(216); //Ñóê±3õê¼»ˉ
uart_init(115200); //′®¿ú3õê¼»ˉ
LED_Init(); //3õê¼»ˉLED
KEY_Init(); //3õê¼»ˉ°′¼ü
SDRAM_Init(); //3õê¼»ˉSDRAM
LCD_Init(); //LCD3õê¼»ˉ
MY_ADC_Init(); //3õê¼»ˉADC1í¨μà5
POINT_COLOR=RED;
LCD_ShowString(30,50,200,16,16,"Apollo STM32F4/F7");
LCD_ShowString(30,70,200,16,16,"ADC TEST");
LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(30,110,200,16,16,"2016/7/12");
POINT_COLOR=BLUE;//éèÖÃ×ÖìåÎaà¶é«
LCD_ShowString(30,130,200,16,16,"ADC1_CH5_VAL:");
LCD_ShowString(30,150,200,16,16,"ADC1_CH5_VOL:0.000V"); //ÏèÔú1춨λÖÃÏÔê¾D¡êyμã
while(1)
{
adcx=Get_Adc_Average(ADC_CHANNEL_5,20);//»ñè¡í¨μà5μÄ×a»»Ö죬20′Îè¡Æ½¾ù
LCD_ShowxNum(134,130,adcx,4,16,0); //ÏÔê¾ADCC2éÑùoóμÄÔ-ê¼Öμ
temp=(float)adcx*(3.3/4096); //»ñ衼ÆËãoóμÄ′øD¡êyμÄêμ¼êμçÑ1Ö죬±èèç3.1111
adcx=temp; //¸3ÖμÕûêy2¿·Ö¸øadcx±äá¿£¬òòÎaadcxÎau16ÕûDÎ
LCD_ShowxNum(134,150,adcx,1,16,0); //ÏÔê¾μçÑ1ÖμμÄÕûêy2¿·Ö£¬3.1111μÄ»°£¬Õaàï¾íêÇÏÔê¾3
temp-=adcx; //°ÑòѾ-ÏÔê¾μÄÕûêy2¿·Öè¥μô£¬áôÏÂD¡êy2¿·Ö£¬±èèç3.1111-3=0.1111
temp*=1000; //D¡êy2¿·Ö3ËòÔ1000£¬àyèç£o0.1111¾í×a»»Îa111.1£¬Ïàμ±óú±£áôèyλD¡êy¡£
LCD_ShowxNum(150,150,temp,3,16,0X80); //ÏÔê¾D¡êy2¿·Ö£¨Ç°Ãæ×a»»ÎaáËÕûDÎÏÔê¾£©£¬ÕaàïÏÔê¾μľíêÇ111.
LED0_Toggle;
delay_ms(250);
}
}
一周热门 更多>