/*************************************************************************//**
* @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] );
}
}
共2条
1/1 1 跳转至页
为何使用M480EADCDMA只能获取2个通道?
关键词: DMA ADC
2楼
设置不对导致逻辑错误。
1、设置采样模块0~3由中断触发,
2、设置采样模块0~10作为中断触发源
3、然后手动启动了0~3采样模块。
第一次:软件设置的通道0采样==》完成后PDMA搬走数据。 此时产生中断,中断又触发0~3采样模块采样
第二次:不确定是软件设置的采样模块1还是中断触发的采样模块0采样==》采样完===》搬运数据 产生中断==》再触发采样
第三次及以后:情况同第二次
中断触发采样:一般选用最大编号的采样模块作为中断源
过程:软件启动最高编号采样模块==》采样完==》产生中断==》触发采样模块依次采样==》最大编号采样模块采样结束==》产生中断==》重复上面动作
建议
建议采用软件按触发,不要使用中断触发,中断触发相当于触发源那个通道会多采样依次。同时使能0~3通道,会依次采样0~3通道==》结束
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
与电子爱好者谈读图二被打赏50分 | |
【FRDM-MCXN947评测】Core1适配运行FreeRtos被打赏50分 | |
【FRDM-MCXN947评测】双核调试被打赏50分 | |
【CPKCORRA8D1B评测】---移植CoreMark被打赏50分 | |
【CPKCORRA8D1B评测】---打开硬件定时器被打赏50分 | |
【FRDM-MCXA156评测】4、CAN loopback模式测试被打赏50分 | |
【CPKcorRA8D1评测】--搭建初始环境被打赏50分 | |
【FRDM-MCXA156评测】3、使用FlexIO模拟UART被打赏50分 | |
【FRDM-MCXA156评测】2、rt-thread MCXA156 BSP制作被打赏50分 | |
【FRDM-MCXN947评测】核间通信MUTEX被打赏50分 |