完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
/*ADC_OVSR:过采样率,取值:2,4,8,16,32,64,128,256*/ #define ADC_OVSR 256 /*ADC_shift:ADC结果右移,取值:0~8*/ #define ADC_shift 4 /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ ADC_InitType ADC_InitStructure; DMA_InitType DMA_InitStructure; __IO uint16_t ADCConvertedValue[256] = {0,}; __IO uint32_t ADCConvertedValue_16 = 0; /* Private function prototypes -----------------------------------------------*/ void RCC_Configuration(void); void GPIO_Configuration(void); /* Private functions ---------------------------------------------------------*/ /** * @Brief Main program * @param None * @retval None */ int main(void) { uint16_t i,j ; /* System clocks configuration */ RCC_Configuration(); /* GPIO configuration ------------------------------------------------------*/ GPIO_Configuration(); /* USART configuration */ UART_Print_Init(115200); /* DMA1 channel1 configuration ----------------------------------------------*/ DMA_Reset(DMA1_Channel1); DMA_DefaultInitParaConfig(&DMA_InitStructure); DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC1->RDOR; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADCConvertedValue; DMA_InitStructure.DMA_Direction = DMA_DIR_PERIPHERALSRC; DMA_InitStructure.DMA_BufferSize = ADC_OVSR; DMA_InitStructure.DMA_PeripheralInc = DMA_PERIPHERALINC_DISABLE; DMA_InitStructure.DMA_MemoryInc = DMA_MEMORYINC_ENABLE; DMA_InitStructure.DMA_PeripheralDataWidth = DMA_PERIPHERALDATAWIDTH_HALFWORD; DMA_InitStructure.DMA_MemoryDataWidth = DMA_MEMORYDATAWIDTH_HALFWORD; DMA_InitStructure.DMA_Mode = DMA_MODE_CIRCULAR; DMA_InitStructure.DMA_Priority = DMA_PRIORITY_HIGH; DMA_InitStructure.DMA_MTOM = DMA_MEMTOMEM_DISABLE; DMA_Init(DMA1_Channel1, &DMA_InitStructure); /* Enable DMA1 channel1 */ DMA_ChannelEnable(DMA1_Channel1, ENABLE); /* ADC1 configuration ------------------------------------------------------*/ ADC_StructInit(&ADC_InitStructure); ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanMode = ENABLE; ADC_InitStructure.ADC_ContinuousMode = ENABLE; ADC_InitStructure.ADC_ExternalTrig = ADC_ExternalTrig_None; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NumOfChannel = 1; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channels configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_1_5); /* Enable ADC1 DMA */ ADC_DMACtrl(ADC1, ENABLE); /* Enable ADC1 */ ADC_Ctrl(ADC1, ENABLE); /* Enable ADC1 reset calibration register */ ADC_RstCalibration(ADC1); /* Check the end of ADC1 reset calibration register */ while(ADC_GetResetCalibrationStatus(ADC1)); /* Start ADC1 calibration */ ADC_StartCalibration(ADC1); /* Check the end of ADC1 calibration */ while(ADC_GetCalibrationStatus(ADC1)); /* Start ADC1 Software Conversion */ ADC_SoftwareStartConvCtrl(ADC1, ENABLE); while (1) { while( DMA_GetITStatus(DMA1_INT_TC1) == SET) { ADCConvertedValue_16 = 0; for(i=0;i ADCConvertedValue_16 += ADCConvertedValue; //过采样求和 ADCConvertedValue_16 = (ADCConvertedValue_16>>ADC_shift)&0xFFFF; //求位移&取16位结果截断 DMA_ClearITPendingBit(DMA1_INT_TC1); printf("ADCConvertedValue_16 = 0x%xrn",ADCConvertedValue_16); } } } /** * @brief Configures the different system clocks. * @param None * @retval None */ void RCC_Configuration(void) { /* ADCCLK = PCLK2/4 */ RCC_ADCCLKConfig(RCC_APB2CLK_Div4); /* Enable peripheral clocks ------------------------------------------------*/ /* Enable DMA1 clocks */ RCC_AHBPeriphClockCmd(RCC_AHBPERIPH_DMA1, ENABLE); /* Enable ADC1 and GPIOA clocks */ RCC_APB2PeriphClockCmd(RCC_APB2PERIPH_ADC1 , ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPERIPH_GPIOA , ENABLE); } /** * @brief Configures the different GPIO ports. * @param None * @retval None */ void GPIO_Configuration(void) { GPIO_InitType GPIO_InitStructure; /* Configure PA0 (ADC Channel0) as analog input -------------------------*/ GPIO_StructInit(&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pins = GPIO_Pins_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_Init(GPIOA, &GPIO_InitStructure); }
|
|
|
相关推荐
|
|
有人有STM8H1K08T连接TM1650的源码吗,可以直接使用的那种,我的代码在烧录之后数码管一直处于熄灭状态
271 浏览 0 评论
【瑞萨RA6E2】瑞萨E2S软件安装过程,等待过程玩下97_e2 studio_ZGZZ
493 浏览 0 评论
589 浏览 0 评论
【原创】【RA4M2-SENSOR开发板评测】低功耗+USB综合测试
891 浏览 0 评论
1436 浏览 2 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
16926 浏览 31 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-4 09:57 , Processed in 0.759275 second(s), Total 71, Slave 51 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖