-
HC32F460 KEUA 和JETA的ADC问题 赏800家园币
大家好,之前购买了几块HC32F460的开发板。其中也包括JETA型号的。 最近有个KEUA的型号需要调试,调试ADC时,发现数据不更新(同样的程序在JETA等开发板上都正常)。 [color=#f00000]//----以下是ADC的配置-----------[/color] [color=#f00000]// ADC初始化[/color] v[color=#0000f0]oid AdcConfig(void)[/color] [color=#0000f0]{[/color] [color=#0000f0] AdcClockConfig();[/color] [color=#0000f0] AdcInitConfig();[/color] [color=#0000f0] AdcChannelConfig();[/color] [color=#0000f0]}[/color] [color=#0000f0] [/color] [color=#f00000]// ADC时钟直接使用 ClkPeriSrcPclk[/color] [color=#0000f0]static void AdcClockConfig(void)[/color] [color=#0000f0]{[/color] [color=#f00000] /* Set bus clock division, depends on the system clock frequency. */[/color] [color=#f00000]// m_stcSysclkCfg.enPclk2Div = ClkSysclkDiv64;[/color] [color=#f00000]// m_stcSysclkCfg.enPclk4Div = ClkSysclkDiv16;[/color] [color=#f00000] [/color] [color=#f00000]// CLK_SysClkConfig(&m_stcSysclkCfg);[/color] [color=#0000f0] CLK_SetPeriClkSource(ClkPeriSrcPclk);[/color] [color=#0000f0] [/color] [color=#0000f0]}[/color] [color=#0000f0] [/color] [color=#0000f0]void AdcInitConfig(void)[/color] [color=#0000f0]{[/color] [color=#0000f0] stc_adc_init_t stcAdcInit;[/color] [color=#0000f0] [/color] [color=#0000f0] MEM_ZERO_STRUCT(stcAdcInit);[/color] [color=#0000f0] [/color] [color=#0000f0] stcAdcInit.enResolution = AdcResolution_12Bit;[/color] [color=#0000f0] stcAdcInit.enDataAlign = AdcDataAlign_Right;[/color] [color=#0000f0] stcAdcInit.enAutoClear = AdcClren_Disable;[/color] [color=#0000f0] stcAdcInit.enScanMode = AdcMode_SAOnce;; [/color][color=#f00000]//单次采样[/color] [color=#f00000] /* 1. Enable ADC1. */[/color] [color=#0000f0] PWC_Fcg3PeriphClockCmd(PWC_FCG3_PERIPH_ADC1, Enable);[/color] [color=#0000f0] [/color][color=#f00000] /* 2. Initialize ADC1. */[/color] [color=#0000f0] ADC_Init(M4_ADC1, &stcAdcInit);[/color] [color=#0000f0]}[/color] [color=#0000f0] [/color] [color=#0000f0] [/color] [color=#0000f0]#define [/color][color=#008000]ADC1_SA_CHANNEL_COUNT[/color][color=#0000f0] (3u)[/color] [color=#0000f0]void AdcChannelConfig(void)[/color] [color=#0000f0]{[/color] [color=#0000f0] stc_adc_ch_cfg_t stcChCfg;[/color] [color=#0000f0] uint8_t au8Adc1SaSampTime[ADC1_SA_CHANNEL_COUNT] = { 0x60,0x80,0x80};[/color] [color=#0000f0] MEM_ZERO_STRUCT(stcChCfg);[/color] [color=#0000f0] [/color] [color=#0000f0] stcChCfg.u32Channel = (ADC1_CH0 | ADC1_CH1| ADC1_CH2);[/color] [color=#0000f0] stcChCfg.u8Sequence = ADC_SEQ_A;[/color] [color=#0000f0] stcChCfg.pu8SampTime = au8Adc1SaSampTime;[/color] [color=#0000f0] [/color][color=#f00000] /* 1. Set the ADC pin to analog mode. */[/color] [color=#0000f0] AdcSetChannelPinMode(M4_ADC1, (ADC1_CH0 | ADC1_CH1| ADC1_CH2), Pin_Mode_Ana); [/color] [color=#f00000] /* 2. Add ADC channel. */[/color] [color=#0000f0] ADC_AddAdcChannel(M4_ADC1, &stcChCfg);[/color] [color=#0000f0]}[/color] [color=#f00000]//---以下是测试的main程序----[/color] [color=#008080]int32_t main(void)[/color] [color=#008080]{[/color] [color=#008080] UseXTAL();[/color][color=#f00000]//使用外部16M晶振[/color] [color=#008080] //ADC初始化[/color] [color=#008080] AdcConfig();[/color] [color=#008080] ADC_StartConvert(M4_ADC1);// ADC软起动[/color] [color=#008080] while(1)[/color] [color=#008080] {[/color] [color=#008080] Ddl_Delay1ms(1000);[/color] [color=#08080] [/color][color=#f0c000]ADC_GetAllData[/color][color=#008080](M4_ADC1, m_au16Adc1Value, ADC1_CH_COUNT);//读取ADC结果[/color] [color=#008080] ADC_ClrEocFlag(M4_ADC1, ADC_SEQ_A);[/color] [color=#008080] ADC_StartConvert(M4_ADC1);[/color][color=#f00000]// ADC软起动--重新启动[/color] [color=#008080] }[/color] [color=#008080]}[/color] 以上代码,在JETA开发板中正常,但是在KEUA板子中,调试发现数值没有变化,即DR寄存器数值的值都没有变化 [color=#f0c000]ADC_GetAllData[/color] 会调用 [color=#f0c000]ADC_ReadAllData[/color] 读取[color=#f0c000]ADCx->DR[/color] static void[color=#f00000] [/color][color=#f0c000]ADC_ReadAllData[/color](const M4_ADC_TypeDef *ADCx, uint16_t *pu16AdcData, uint8_t u8Length) { uint8_t i; __IO const uint16_t *pu16DataReg =[color=#f00000] [/color][color=#f0c000]&(ADCx->DR0);[/color] for (i = 0u; i < u8Length; i++) { pu16AdcData[i] = pu16DataReg[i]; } } 电路应该是没有问题的,万用表测量的相关ADC的IO管脚,都是有电平的,且电平也是在变化. 不知是哪个环节出了问题? 谢谢
23846浏览量 7回复量 关注量