完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
/**
* @brief Set the reference voltage selection. * @param[in] adc Base address of ADC module * @param[in] u32Ref The reference voltage selection. Valid values are: * - \ref ADC_REFSEL_POWER * - \ref ADC_REFSEL_INT_VREF * - \ref ADC_REFSEL_VREF * @return None * \hideinitializer */ #define ADC_SET_REF_VOLTAGE(adc, u32Ref) (ADC->CR = (ADC->CR & ~ADC_CR_REFSEL_Msk) | u32Ref) 那个例子中的是出自这个文件。 /**************************************************************************//** * @file main.c * @version V1.00 * $Revision: 10 $ * $Date: 15/06/16 7:22p $ * @brief Convert ADC channel 0, 1, 2 in Continuous Scan mode and print conversion results. * * @note * Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved. *****************************************************************************/ #include #include "Nano100Series.h" volatile uint8_t u8ADF; void ADC_IRQHandler(void); void ADC_IRQHandler(void) { uint32_t u32Flag; // Get ADC conversion finish interrupt flag u32Flag = ADC_GET_INT_FLAG(ADC, ADC_ADF_INT); if(u32Flag & ADC_ADF_INT) { uint32_t u32Result; u32Result = ADC_GET_CONVERSION_DATA(ADC, 0); printf("Channel 0 conversion result is 0x%x\n",u32Result); u32Result = ADC_GET_CONVERSION_DATA(ADC, 1); printf("Channel 1 conversion result is 0x%x\n",u32Result); u32Result = ADC_GET_CONVERSION_DATA(ADC, 2); printf("Channel 2 conversion result is 0x%x\n",u32Result); } ADC_CLR_INT_FLAG(ADC, u32Flag); } /*---------------------------------------------------------------------------------------------------------*/ /* Init System Clock */ /*---------------------------------------------------------------------------------------------------------*/ void SYS_Init(void) { /* Unlock protected registers */ SYS_UnlockReg(); /* Set HCLK source form HXT and HCLK source divide 1 */ CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HXT,CLK_HCLK_CLK_DIVIDER(1)); /* Enable external 12MHz HXT, 32KHz LXT and HIRC */ CLK_EnableXtalRC(CLK_PWRCTL_HXT_EN_Msk | CLK_PWRCTL_LXT_EN_Msk | CLK_PWRCTL_HIRC_EN_Msk); /* Waiting for clock ready */ CLK_WaitClockReady(CLK_CLKSTATUS_HXT_STB_Msk | CLK_CLKSTATUS_LXT_STB_Msk | CLK_CLKSTATUS_HIRC_STB_Msk); /* Set HCLK frequency 42MHz */ CLK_SetCoreClock(42000000); /* Enable IP clock */ CLK_EnableModuleClock(UART0_MODULE); /* Enable ADC clock */ CLK_EnableModuleClock(ADC_MODULE); /* Select IP clock source */ CLK_SetModuleClock(UART0_MODULE,CLK_CLKSEL1_UART_S_HXT,CLK_UART_CLK_DIVIDER(1)); /*---------------------------------------------------------------------------------------------------------*/ /* Init I/O Multi-function */ /*---------------------------------------------------------------------------------------------------------*/ /* Set PA multi-function pins for UART0 RXD and TXD */ SYS->PB_L_MFP &= ~( SYS_PB_L_MFP_PB0_MFP_Msk | SYS_PB_L_MFP_PB1_MFP_Msk); SYS->PB_L_MFP |= (SYS_PB_L_MFP_PB0_MFP_UART0_RX | SYS_PB_L_MFP_PB1_MFP_UART0_TX ); /* Set PB multi-function pins for Clock Output */ SYS->PB_H_MFP = ( SYS->PB_H_MFP & ~SYS_PB_H_MFP_PB12_MFP_Msk ) | SYS_PB_H_MFP_PB12_MFP_CKO; /* Set PA multi-function pins for ADC */ SYS->PA_L_MFP &= ~(SYS_PA_L_MFP_PA0_MFP_Msk | SYS_PA_L_MFP_PA1_MFP_Msk | SYS_PA_L_MFP_PA2_MFP_Msk); SYS->PA_L_MFP |= SYS_PA_L_MFP_PA0_MFP_ADC_CH0 | SYS_PA_L_MFP_PA1_MFP_ADC_CH1 | SYS_PA_L_MFP_PA2_MFP_ADC_CH2; /* Disable PA.0 PA.1 PA.2 digital input path */ PA->OFFD |= (((1<<0)|(1<<1)|(1<<2)) << GP_OFFD_OFFD_Pos); /* Lock protected registers */ SYS_LockReg(); } void UART0_Init() { /*---------------------------------------------------------------------------------------------------------*/ /* Init UART */ /*---------------------------------------------------------------------------------------------------------*/ UART_Open(UART0, 115200); } int32_t main (void) { /* Init System, IP clock and multi-function I/O In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register if necessary */ SYS_Init(); /* Init UART0 for printf */ UART0_Init(); printf("\nThis sample code demonstrate ADC continuous scan conversion\n"); printf("It convert channel 0,1,2 continuously and print conversion result\n"); // Enable channel 0,1,2 ADC_Open(ADC, ADC_INPUT_MODE_SINGLE_END, ADC_OPERATION_MODE_CONTINUOUS, (ADC_CH_0_MASK | ADC_CH_1_MASK | ADC_CH_2_MASK)); // Set reference voltage to AVDD ADC_SET_REF_VOLTAGE(ADC, ADC_REFSEL_POWER); // Power on ADC ADC_POWER_ON(ADC); // Enable ADC ADC_IF interrupt ADC_EnableInt(ADC, ADC_ADF_INT); NVIC_EnableIRQ(ADC_IRQn); ADC_START_CONV(ADC); while(1); } /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/ |
|
相关推荐
1个回答
|
|
NANO100系列的ADC参考电压可以选择ADC_REFSEL_POWER或ADC_REFSEL_INT_VREF。选择ADC_REFSEL_POWER时,参考电压为AVDD;选择ADC_REFSEL_INT_VREF时,参考电压为内部基准电压(1.024V) 。根据实际应用需求进行选择。
|
|
|
|
只有小组成员才能发言,加入小组>>
705 浏览 0 评论
1114 浏览 1 评论
2491 浏览 5 评论
2826 浏览 9 评论
移植了freeRTOS到STMf103之后显示没有定义的原因?
2671 浏览 6 评论
使用eim外接fpga可是端口一点反应都没有有没有大哥指点一下啊
661浏览 9评论
671浏览 7评论
请教大神怎样去解决iMX6Q在linux3.0.35内核上做AP失败的问题呢
789浏览 6评论
634浏览 5评论
679浏览 5评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 21:06 , Processed in 1.049502 second(s), Total 80, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号