现在我想配置一个 ADC 来检测电池电压。我用的是RT1176
单片机,我用的管脚是GPIO_AD_34(J16),有很多复用功能。现在我使用路由IOMUXC_GPIO_AD_34_XBAR1_INOUT18,并开启相关配置,发现可以进入ADC中断,但读取数据始终为0,怀疑是我的配置有问题,但是进不去找到了,你可以帮我让我知道配置错误的地方。附近会给我我的ADC
这是我的代码:
#define DEMO_ADC_BASE LPADC1
#define DEMO_ADC_USER_CHANNEL 0U
#define DEMO_ADC_USER_CMDID 1U
#define DEMO_ADC_CHANNEL_GROUP 0U
#define DEMO_ADC_ETC_BASE ADC_ETC
#define DEMO_ADC_ETC_TRIGGER_GROUP 3U
#define DEMO_ADC_ETC_CHANNEL 1U
#define DEMO_ADC_ETC_DONE0_Handler ADC_ETC_IRQ0_IRQHandler
void ADC_ETC_Configura
tion(void)
{
adc_etc_config_t adcEtcConfig;
adc_etc_trigger_config_t adcEtcTriggerConfig;
adc_etc_trigger_chain_config_t adcEtcTriggerChainConfig;
/* 初始化 ADC_ETC。*/
ADC_ETC_GetDefaultConfig(&adcEtcConfig);
adcEtcConfig.XBARtriggerMask = 0x08U; /* 启用外部 XBAR trigger3。*/
ADC_ETC_Init(DEMO_ADC_ETC_BASE, &adcEtcConfig);
/* 设置外部 XBAR trigger0 配置。*/
adcEtcTriggerConfig.enableSyncMode = false;
adcEtcTriggerConfig.enableSWTriggerMode = true;
adcEtcTriggerConfig.triggerChainLength = 0U; /* 链长 1. */
adcEtcTriggerConfig.triggerPriority = 0U;
adcEtcTriggerConfig.sampleIntervalDelay = 0U;
adcEtcTriggerConfig.initialDelay = 0U;
ADC_ETC_SetTriggerConfig(DEMO_ADC_ETC_BASE, DEMO_ADC_ETC_TRIGGER_GROUP, &adcEtcTriggerConfig);
/* 设置外部 XBAR trigger0 chain0 配置。*/
adcEtcTriggerChainConfig.enableB2BMode = false;
adcEtcTriggerChainConfig.ADCHCRegisterSelect = 1U << DEMO_ADC_CHANNEL_GROUP; /* 选择要触发的 ADC_HC0 寄存器。*/
adcEtcTriggerChainConfig.ADCChannelSelect = DEMO_ADC_ETC_CHANNEL; /* ADC_HC0 将被触发以采样相应的通道。*/
adcEtcTriggerChainConfig.InterruptEnable = kADC_ETC_Done0InterruptEnable; /* 启用 Done0 中断。*/
#if defined(FSL_FEATURE_ADC_ETC_HAS_TRIGm_CHAIN_a_b_IEn_EN) && FSL_FEATURE_ADC_ETC_HAS_TRIGm_CHAIN_a_b_IEn_EN
adcEtcTriggerChainConfig.enableIrq = true; /* 启用 IRQ。*/
#endif /* FSL_FEATURE_ADC_ETC_HAS_TRIGm_CHAIN_a_b_IEn_EN */
/* 配置触发组链0. */
ADC_ETC_SetTriggerChainConfig(DEMO_ADC_ETC_BASE, DEMO_ADC_ETC_TRIGGER_GROUP, 0U, &adcEtcTriggerChainConfig);
}
void LPADC_Configuration(void)
{
lpadc_config_t lpadcConfig;
lpadc_conv_command_config_t lpadcCommandConfig;
lpadc_conv_trigger_config_t lpadcTriggerConfig;
/* 初始化 ADC 模块。*/
LPADC_GetDefaultConfig(&lpadcConfig);
LPADC_Init(DEMO_ADC_BASE, &lpadcConfig);
#if (defined(FSL_FEATURE_LPADC_HAS_CFG_CALOFS) && FSL_FEATURE_LPADC_HAS_CFG_CALOFS)
/* 进行偏移校准。*/
LPADC_DoOffsetCalibration(DEMO_ADC_BASE, SystemCoreClock);
#endif /* FSL_FEATURE_LPADC_HAS_CFG_CALOFS */
/* 设置转换 CMD 配置。*/
LPADC_GetDefaultConvCommandConfig(&lpadcCommandConfig);
lpadcCommandConfig.channelNumber = DEMO_ADC_USER_CHANNEL;
LPADC_SetConvCommandConfig(DEMO_ADC_BASE, DEMO_ADC_USER_CMDID, &lpadcCommandConfig);
/* 设置触发器配置。*/
LPADC_GetDefaultConvTriggerConfig(&lpadcTriggerConfig);
lpadcTriggerConfig.targetCommandId = DEMO_ADC_USER_CMDID;
lpadcTriggerConfig.enableHardwareTrigger = true;
LPADC_SetConvTriggerConfig(DEMO_ADC_BASE, 0U, &lpadcTriggerConfig);
}
void DEMO_ADC_ETC_DONE0_Handler(void)
{
ADC_ETC_ClearInterruptStatusFlags(DEMO_ADC_ETC_BASE, kADC_ETC_Trg3TriggerSource, kADC_ETC_Done0StatusFlagMask);
g_AdcConversionDoneFlag = true;
/* 从触发源链 0 中获取结果 */
g_AdcConversionValue = ADC_ETC_GetADCConversionValue(DEMO_ADC_ETC_BASE, DEMO_ADC_ETC_TRIGGER_GROUP, 1U);
__DSB();
}
而 (1)
{
g_AdcConversionDoneFlag = false;
PRINTF("按任意键获取用户通道的ADC值。rn");
获取字符();
ADC_ETC_DoSoftwareTrigger(DEMO_ADC_ETC_BASE, DEMO_ADC_ETC_TRIGGER_GROUP); /* 执行软件 XBAR trigger3。*/
while (!g_AdcConversionDoneFlag)
{
}
PRINTF("ADC转换值为%drn", g_AdcConversionValue);
}