我有一块M453VG6AE的开发板,买了一本《ARM Cortex-M4微控制器原理与实践》。
可是上面的AD例程不完整,我尝试着写了一下,编译没问题。
可是不仅中断。代码如下,请大神指教,哪里有问题?谢谢!
#include "stdio.h"
#include "M451Series.h"
#include "Common.h"
#include "Typedef.h"
#include "SmartM_M4.H"
VOLATILE BOOL g_unAdcIntFlag=0;
UINT32 ADC_Read(VOID)
{
//Æô¶¯²ÉÑùÄ£¿é4
EADC_START_CONV(EADC,(0x1<<4));
//µÈ´ý²ÉÑùÄ£¿é4ת»»½áÊø
while(g_unAdcIntFlag==0);
g_unAdcIntFlag=0;
//·µ»Ø²ÉÑùÄ£¿é4µÄÊý¾ÝÖµ
return EADC_GET_CONV_DATA(EADC,4);
}
int32_t main(void)
{
UINT32 temp;
PROTECT_REG
(
SYS_Init(PLL_CLOCK);
//ʹÄÜADCʱÖÓÄ£¿é
CLK_EnableModuleClock(EADC_MODULE);
//ÉèÖÃADCʱÖÓԴΪPLL,²¢½øÐÐ8·ÖƵ£¬¼´ADCʱÖÓƵÂÊ=72MHz/8=9MHz
CLK_SetModuleClock(EADC_MODULE,0,CLK_CLKDIV0_EADC(8));
UART0_Init(115200);
)
printf("+----------------------------------+\n");
printf("| ADC Sample Code |\n");
printf("+----------------------------------------+\n\n");
//ÉèÖÃADCÄÚ²¿²ÉÑùʱ¼äΪ6¸öADCʱÖÓ
EADC_SetInternalSampleTime(EADC,6);
//ÅäÖÃPB0Òý½ÅΪADCÄ£ÄâÐźÅÊäÈëÒý½Å
SYS->GPB_MFPL&=~(SYS_GPB_MFPL_PB0MFP_Msk);
SYS->GPB_MFPL|=(SYS_GPB_MFPL_PB0MFP_EADC_CH0);
//ÉèÖÃADCÊäÈëģʽΪµ¥´ÎÍê³É£¬Í¬Ê±Ê¹ÄÜA/Dת»»Æ÷
EADC_Open(EADC,EADC_CTL_DIFFEN_SINGLE_END);
//ÅäÖòÉÑùÄ£¿é4×÷ΪģÄâͨµÀÊäÈë0£¬Í¬Ê±ÉèÖÃADINT0´¥·¢Ô´
EADC_ConfigSampleModule(EADC,4,EADC_ADINT0_TRIGGER,0);
//ʹÄÜADC0µÄ²ÉÑùÄ£¿é4ÖжÏ
EADC_ENABLE_INT(EADC,0X1);
EADC_ENABLE_SAMPLE_MODULE_INT(EADC,0,(0x1<<4));
//ʹÄÜNVIC ADC0_0 IRQ ÖжÏ
NVIC_EnableIRQ(ADC00_IRQn);
while(1)
{
temp=ADC_Read();
printf("%d\r\n",temp);
Delayms(1000);
}
}
VOID ADC00_IRQHandler(VOID)
{
if(EADC_GET_INT_FLAG(EADC,4)==1)
{
EADC_CLR_INT_FLAG(EADC,4);
g_unAdcIntFlag=1;
}
}
|