完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
/*************************************************************************//**
* @file main.c * @version V1.00 * @brief A project template for M480 MCU. * * @copyright (C) 2016 Nuvoton Technology Corp. All rights reserved. *****************************************************************************/ #include #include "NuMicro.h" #define ADC_PDMA_CH (4) #define ADC_PDMA_OPENED_CH (1 << ADC_PDMA_CH) #define ADC_DMA_SAMPLE_COUNT (4) uint16_t pdmaConvertedData[ADC_DMA_SAMPLE_COUNT] = {0}; enum { ADC0_CH0 = 0, ADC0_CH1, ADC0_CH2, ADC0_CH3, ADC0_CH4, ADC0_CH5, ADC0_CH6, ADC0_CH7, ADC0_CH8, ADC0_CH9, ADC0_CH10, ADC0_CH11, ADC0_CH12, ADC0_CH13, ADC0_CH14, ADC0_CH15, ADC0_CH16_BAND_GAP_VOLT, ADC0_CH17_TEMP_SENSOR, ADC0_CH18_VBAT, ADC_CH_DEFAULT } ADC_CH_TypeDef; typedef enum { flag_ADC_Band_GAP = 0, flag_ADC_Data_Ready, flag_ADC_Sensor_Ready, flag_PDMA_Trans_Data_Ready, flag_DEFAULT } Flag_Index; uint32_t BitFlag = 0; #define BitFlag_ON(flag) (BitFlag|=flag) #define BitFlag_OFF(flag) (BitFlag =~flag) #define BitFlag_READ(flag) ((BitFlag flag)?1:0) #define ReadBit(bit) (uint32_t)(1 /* Select PDMA request source as ADC RX */ PDMA_SetTransferMode(PDMA, ADC_PDMA_CH, PDMA_EADC0_RX, FALSE, 0); /* Set PDMA as single request type for ADC */ PDMA_SetBurstType(PDMA, ADC_PDMA_CH, PDMA_REQ_SINGLE, PDMA_BURST_128); PDMA_EnableInt(PDMA, ADC_PDMA_CH, PDMA_INT_TRANS_DONE); NVIC_EnableIRQ(PDMA_IRQn); PDMA_Trigger(PDMA, ADC_PDMA_CH); /* ADC enable PDMA transfer */ EADC_ENABLE_PDMA(EADC); } void EADC00_IRQHandler(void) { // printf(" EADC00_IRQHandlerrn"); EADC_CLR_INT_FLAG(EADC, EADC_STATUS2_ADIF0_Msk); /* Clear the A/D ADINT0 interrupt flag */ } void ADC_Convert_Ext_Channel(void) { /* Set input mode as single-end, and Single mode*/ EADC_Open(EADC, EADC_CTL_DIFFEN_SINGLE_END); EADC_SetExtendSampletime(EADC, 0x0f, 0x3F); EADC_ConfigSampleModule(EADC, 0, EADC_ADINT0_TRIGGER, 0); EADC_ConfigSampleModule(EADC, 1, EADC_ADINT0_TRIGGER, 1); EADC_ConfigSampleModule(EADC, 2, EADC_ADINT0_TRIGGER, 2); EADC_ConfigSampleModule(EADC, 3, EADC_ADINT0_TRIGGER, 3); EADC_CLR_INT_FLAG(EADC, EADC_STATUS2_ADIF0_Msk); EADC_ENABLE_INT(EADC, (BIT0 << 0)); EADC_ENABLE_SAMPLE_MODULE_INT(EADC, 0, 0x7FF); NVIC_EnableIRQ(EADC00_IRQn); PDMA_Init(); EADC_START_CONV(EADC, 0x0F); } void SYS_Init(void) { /*---------------------------------------------------------------------------------------------------------*/ /* Init System Clock */ /*---------------------------------------------------------------------------------------------------------*/ /* Unlock protected registers */ SYS_UnlockReg(); /* Set XT1_OUT(PF.2) and XT1_IN(PF.3) to input mode */ PF->MODE = ~(GPIO_MODE_MODE2_Msk | GPIO_MODE_MODE3_Msk); /* Enable External XTAL (4~24 MHz) */ CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk); /* Waiting for 12MHz clock ready */ CLK_WaitClockReady(CLK_STATUS_HXTSTB_Msk); /* Set core clock as PLL_CLOCK from PLL */ CLK_SetCoreClock(FREQ_192MHZ); /* Set PCLK0/PCLK1 to HCLK/2 */ CLK->PCLKDIV = (CLK_PCLKDIV_APB0DIV_DIV2 | CLK_PCLKDIV_APB1DIV_DIV2); /* Enable UART clock */ CLK_EnableModuleClock(UART0_MODULE); /* Select UART clock source from HXT */ CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART0SEL_HXT, CLK_CLKDIV0_UART0(1)); /* Enable EADC module clock */ CLK_EnableModuleClock(EADC_MODULE); /* EADC clock source is 96MHz, set divider to 8, EADC clock is 96/8 MHz */ CLK_SetModuleClock(EADC_MODULE, 0, CLK_CLKDIV0_EADC(8)); CLK_EnableModuleClock(PDMA_MODULE); /* Update System Core Clock */ /* User can use SystemCoreClockUpdate() to calculate SystemCoreClock. */ SystemCoreClockUpdate(); /* Set GPB multi-function pins for UART0 RXD and TXD */ SYS->GPB_MFPH = ~(SYS_GPB_MFPH_PB12MFP_Msk | SYS_GPB_MFPH_PB13MFP_Msk); SYS->GPB_MFPH |= (SYS_GPB_MFPH_PB12MFP_UART0_RXD | SYS_GPB_MFPH_PB13MFP_UART0_TXD); PB->MODE = ~(GPIO_MODE_MODE0_Msk | GPIO_MODE_MODE1_Msk | GPIO_MODE_MODE2_Msk | GPIO_MODE_MODE3_Msk); SYS->GPB_MFPL = ~(SYS_GPB_MFPL_PB0MFP_Msk | SYS_GPB_MFPL_PB1MFP_Msk | SYS_GPB_MFPL_PB2MFP_Msk | SYS_GPB_MFPL_PB3MFP_Msk); SYS->GPB_MFPL |= (SYS_GPB_MFPL_PB0MFP_EADC0_CH0 | SYS_GPB_MFPL_PB1MFP_EADC0_CH1 | SYS_GPB_MFPL_PB2MFP_EADC0_CH2 | SYS_GPB_MFPL_PB3MFP_EADC0_CH3); GPIO_DISABLE_DIGITAL_PATH(PB, BIT0 | BIT1 | BIT2 | BIT3); /* Set reference voltage to external pin (3.3V) */ SYS_SetVRef(SYS_VREFCTL_VREF_PIN); /* Lock protected registers */ SYS_LockReg(); } /* * This is a template project for M480 series MCU. Users could based on this project to create their * own application without worry about the IAR/Keil project settings. * * This template application uses external crystal as HCLK source and configures UART0 to print out * "Hello World", users may need to do extra system configuration based on their system design. */ int main() { SYS_Init(); /* Init UART to 115200-8n1 for print message */ UART_Open(UART0, 115200); printf("rnCLK_GetCPUFreq : %8drn", CLK_GetCPUFreq()); printf("CLK_GetHXTFreq : %8drn", CLK_GetHXTFreq()); printf("CLK_GetLXTFreq : %8drn", CLK_GetLXTFreq()); printf("CLK_GetPCLK0Freq : %8drn", CLK_GetPCLK0Freq()); printf("CLK_GetPCLK1Freq : %8drn", CLK_GetPCLK1Freq()); ADC_Convert_Ext_Channel(); /* Got no where to go, just loop forever */ while(1) { pdmaConvertedData[0] = EADC_GET_CONV_DATA(EADC, 0); pdmaConvertedData[1] = EADC_GET_CONV_DATA(EADC, 1); pdmaConvertedData[2] = EADC_GET_CONV_DATA(EADC, 2); pdmaConvertedData[3] = EADC_GET_CONV_DATA(EADC, 3); printf("%04d,%04d,%04d,%04d rn", pdmaConvertedData[0], pdmaConvertedData[1], pdmaConvertedData[2], pdmaConvertedData[3] ); } } /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/ |
|
相关推荐
1个回答
|
|
设置不对导致逻辑错误。
1、设置采样模块0~3由中断触发, 2、设置采样模块0~10作为中断触发源 3、然后手动启动了0~3采样模块。 第一次:软件设置的通道0采样==》完成后PDMA搬走数据。 此时产生中断,中断又触发0~3采样模块采样 第二次:不确定是软件设置的采样模块1还是中断触发的采样模块0采样==》采样完===》搬运数据 产生中断==》再触发采样 第三次及以后:情况同第二次 中断触发采样:一般选用最大编号的采样模块作为中断源 过程:软件启动最高编号采样模块==》采样完==》产生中断==》触发采样模块依次采样==》最大编号采样模块采样结束==》产生中断==》重复上面动作 建议 建议采用软件按触发,不要使用中断触发,中断触发相当于触发源那个通道会多采样依次。同时使能0~3通道,会依次采样0~3通道==》结束 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-使用AHT20进行环境监测之AHT20传感器介绍
203 浏览 0 评论
761 浏览 0 评论
806 浏览 1 评论
基于瑞萨FPB-RA4E2智能床头灯项目——1编译环境搭建与点亮驱动ws2812全彩LED
743 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-LCD显示图片编程示例之介绍mmap
1195 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11808 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-28 02:17 , Processed in 0.669156 second(s), Total 76, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号