我最近正在调试一个LCP2214的应用,调试外部中断时,总无法触发,电路设计是用P0.09和P0.20内部或门高电平触发INT3,lpc2214_err.pdf中提出了一些芯片BUG,我照着修改程序,还是无法触发中断,郁闷!请用过的朋友指点一下,无胜感激!
初始化代码如下:
uint32 VPBDIV_BAK; //lpc2214_err.pdf要求在修改EXTMODE和EXTPOLAR时候保护VPBDIV值
//IO配置 static void BSP_IO_Init (void) { //用P0.09和P0.20内部或门高电平触发INT3, PINSEL0 = 0xA00C1555; //1010 0000 0000 1100 0001 0101 0101 0101 //PINSEL0的19:18(P0.09) 为11 ^^ PINSEL1 = 0x00000301; //0000 0000 0000 0000 0000 0011 0000 0001 //PINSEL1的9:8(P0.20) 为11 ^^ PINSEL2 = 0x0D800914; //0000 1101 1000 0000 0000 1001 0001 0100 }
//外中断3初始化,这个初始化我保证在其他初始化之后,也就是说不会再对VPBDIV,EXTMODE,EXTPOLAR 等寄存器做任何操作
static void ExInt_Init(void) { VICIntSelect &= (~(1 << VIC_EINT3));
VICSoftIntClr = 0xFFFFFFFF; EXTINT = 0x0F; //清除中断标志 EXTWAKE = 0x00; //不使用中断唤醒功能
VPBDIV_BAK = VPBDIV ;//备份VPBDIV VPBDIV_BAK = VPBDIV ;//连续两个读指令保证获取正确的VPBDIV
/*Philips Semiconductors LPC2214 Erratasheet page6
VPBDIV.1 Incorrect read of VPBDIV Introduction: The Peripheral Bus Divider (VPBDIV) divides the processor clock (CCLK) by one, two, or four. This is the clock that is provided to the peripheral bus. Problem: Reading the VPBDIV register may return an incorrect value. Work-around: Performing two consecutive reads of the VPBDIV assures that the correct value is returned. */ VPBDIV = 0 ;// EXTMODE = 0x07;//外中断3电平触发 VPBDIV = 0x07 ;//lpc2214_err.pdf要求
VPBDIV = 0 ;// EXTPOLAR = 0x08 ;//外中断3高电平触发 VPBDIV = 0x08 ; //lpc2214_err.pdf要求 VPBDIV = VPBDIV_BAK ;//恢复VPBDIV值 /*这个操作按照PDF要求,详见后面说明*/
VICVectAddr4 = (CPU_INT32U)EXINT3_ISR_Handler; //设置中断服务程序地址 VICVectCntl4 = 0x20 | VIC_EINT3; VICIntEnable = (1 << VIC_EINT3);//使能中断触发 EXTINT = 0x0F; }
中断程序如下:从来没进过,所以先可以不看。 void __irq EXINT3_ISR_Handler(void) { uint32 i; i = IO0SET; if( (i&BEEPCON)==0 ) IO0SET = BEEPCON; else IO0CLR = BEEPCON; while( (EXTINT&1<<3)!=0 ) EXTINT = 1<<3; VICVectAddr = 0; }
/*Philips Semiconductors LPC2214 Erratasheet page5-6
EXTINT.1 Corruption of VPBDIV via EXTPOLAR or EXTMODE
Introduction: The VPBDIV register controls the rate of the VPB clock in relation to the processor clock.EXTPOLAR and EXTMODE determine the operating parameters of the external interrupts.
Problem: A write to either the external interrupt polarity register (EXTPOLAR) or the external interrupt mode register (EXTMODE) will corrupt the VPBDIV register. A read of either EXTPOLAR or EXTMODE will be corrupted BY the VPBDIV register. If VPBDIV is “1” or “2” prior to any write to EXTPOLAR or EXTMODE, the CPU will hang up on the write to EXTPOLAR or EXTMODE.
Work-around: If VPBDIV is non-zero, write all zeroes to VPBDIV before reading or writing EXTMODE or EXTPOLAR, then write the proper value back to VPBDIV. In most applications this is a known and fixed value, but if there is a possibility of dynamic changes in VPBDIV, software will need to read VPBDIV, write zero to VPBDIV, read or write EXTMODE and/or EXTPOLAR, and then rewrite the value previously read from VPBDIV.
EXTINT.2 Incorrect setting of EXTMODE and/or EXTPOLAR register while trying to set them to desired value
Introduction: EXTPOLAR and EXTMODE determine the operating parameters of the external interrupts.
Problem: As an illustration, trying to set EXTMODE to 0x1 or 0xd would result in EXTMODE to be set to 0x0 instead.
Work-around: This problem is related to EXTINT.1 and hence the same workaround applies with an additional step.
The steps involved in the configuration of the EXTMODE and/or EXTPOLAR would be as follow:- 1. Write 0x0 to VPBDIV 2. Write the desired value to EXTMODE or EXTPOLAR register 3. Write the same value to VPBDIV (additional step) 4. Restore the VPBDIV to the previously saved value or simply write to
the register again with the desired value. Code sample for setting EXTMODE and EXTPOLAR to 0x1: VPBDIV = 0x0; /* EXTMODE */ EXTMODE = 0x1; VPBDIV = 0x1; VPBDIV = 0x0; /* EXTPOLAR */ EXTPOLAR = 0x1; VPBDIV = 0x1; VPBDIV = 0x0; /* Setting VPBDIV */ Note: While testing this in a debugger environment, please don’t single-step through these steps. A breakpoint could be placed after Step 4 andyou would see the EXTMODE and EXTPOLAR registers reflecting the correct values. */
真不知道我哪里搞错了?谢谢! |