完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
//DMA方式ADC转换
void AdcInit_DMA(void) { //ADC相关管脚初始化 GPIO_InitTypeDef GPIO_InitStructure; /* Configure PB.00 PB.01 (ADC Channel 08) as analog input -------------------------*/ //GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 ; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Configure PA.00 PA.01 PA.07 PA.06 as analog input -------------------------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure PC.00-05 as analog input -------------------------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; GPIO_Init(GPIOC, &GPIO_InitStructure); /* DMA1 channel1 configuration ----------------------------------------------*/ DMA_DeInit(DMA1_Channel1); DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADCConvertedValue; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 16; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel1, &DMA_InitStructure); /* Enable DMA1 channel1 */ DMA_Cmd(DMA1_Channel1, ENABLE); /* ADC1 configuration ------------------------------------------------------*/ 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 = 16; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channel14 configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_71Cycles5); //AD输出1通道 ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 2, ADC_SampleTime_71Cycles5); //AD输出2通道 ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 3, ADC_SampleTime_71Cycles5); //AD输出3通道 ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 4, ADC_SampleTime_71Cycles5); //AD输出4通道 ADC_RegularChannelConfig(ADC1, ADC_Channel_5, 5, ADC_SampleTime_71Cycles5); //AD输出5通道 ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 6, ADC_SampleTime_71Cycles5); //AD输出6通道 ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 7, ADC_SampleTime_71Cycles5); //AD输出7通道 ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 8, ADC_SampleTime_71Cycles5); //AD输出8通道 ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 9, ADC_SampleTime_71Cycles5); //AD输出9通道 ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 10, ADC_SampleTime_71Cycles5); // ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 11, ADC_SampleTime_71Cycles5); // ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 12, ADC_SampleTime_71Cycles5); // ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 13, ADC_SampleTime_71Cycles5); // ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 14, ADC_SampleTime_71Cycles5); // ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 15, ADC_SampleTime_71Cycles5); // ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 16, ADC_SampleTime_239Cycles5); // /* Enable ADC1 DMA */ ADC_DMACmd(ADC1, ENABLE); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* Enable ADC1 reset calibaration register */ ADC_ResetCalibration(ADC1); /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1)); /* Start ADC1 calibaration */ ADC_StartCalibration(ADC1); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1)); /* Start ADC1 Software Conversion */ ADC_SoftwareStartConvCmd(ADC1, ENABLE); ADC_TempSensorVrefintCmd(ENABLE); //温度检测允许 /* Enable ADC1 EOC interupt */ ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE); } |
|
|
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;这里只有6个
你的ADC总共使用了14个通道,而你的DMA缓冲区却是16个通道,数据会出现交叉的。 |
|
|
|
和外围电路也是有关系的
|
|
|
|
万用表精度是多少?是否有误差。
|
|
|
|
不好意思,这段时间出差了,没有过来看。 表是5位半的。我测试了好几个板子,都是这个电压点不准,万用表测的结果是线性的,而单片机一到这个电压点就不准了,过了这个点又准了。关于通道的问题,因为这个底层不是我写的,我再研究一下,谢谢回复。
|
|
|
|
外围很简单,我就弄了一个滑动变阻器,一边滑动,一边用万用表测电压,一边看单片机读出的电压
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1129 浏览 0 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1075 浏览 2 评论
2175 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
1269 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1693 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-26 09:41 , Processed in 0.783477 second(s), Total 84, Slave 67 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号