您的位置:首页 > 其它

对于cc2530GPIO中断的一点理解。

2015-02-22 23:32 253 查看
近日在学习cc2530.想要写个小程序,使用P0.0作为外部中断源,P0.0设置为输入口,当P0.0输入低电平,触发中断,进入中断服务程序。中断触发方式为上升沿触发。

阅读cc2530的datasheet知道和P0口中断相关的寄存器(部分具体到相关位)有以下这些:

a) IEN1.P0IE;//中断使能寄存器,CPU

b) IRCON.P0IF//中断标志寄存器,CPU

c) P0IFG
//端口0中断状态标志寄存器

d) P0IEN
//端口0中断使能寄存器

e) PICTL.P0ICON//端口中断控制寄存器

我的疑问1:设置各个中断相关寄存器的先后顺序如何安排?

答:手册上有这样一段文字:

In orderto enableanyofthe interrupts, the following stepsmustbetaken:

1. Clearinterrupt flags.

2. Set individual interrupt-enable bit in the peripheralsSFRregister,if any.

3. Setthe correspondingindividual interrupt-enable bitin the IEN0, IEN1, orIEN2registerto 1.

4. Enableglobalinterrupt bysettingthe EAbitin IEN0to 1.

5. Beginthe interrupt serviceroutine atthe correspondingvectoraddressofthat interrupt. SeeTable2-5

for addresses.

了解后知道意思是要:

1. 清中断标志位。这里就是设置IRCON.P0IF和P0IFG.

2. 设置中断相关的寄存器的中断使能位为1.这里是设置P0IEN.(!这里是器件相关的中断寄存器优先于CPU的)

3. 设置中断相关寄存器IEN0,IEN1,IEN2中相应的中断使能位为1.(这里是和CPU中断相关的。)

4. 设置IEN0.EA为1.开总中断。(这里是和CPU中断相关的)

5. 中断发生时进入中断服务程序。

按照上述顺序即可。

我的疑问2:清中断标志是先清CPU中断标志寄存器还是先清源中断标志寄存器?(这里就是IRCON.P0IF和P0IFG)

答:手册上有了这样一段文字:

Asageneralrule for pulsedoredgeshapedinterrupt sources,one

shouldclearCPUinterrupt flag registerspriorto clearingsourceflag bit,if available,for flags that arenot

automaticallycleared.Forlevel sources,onemustclearthe sourcepriorto clearingthe CPUflag.

了解后知道意思是要:当不能硬件自动清除标志位时。中断触发方式为脉冲触发方式或边沿触发方式,则先清CPU中断标志寄存器。当中断触发方式为电平触发方式,则先清源中断标志寄存器。

阅读手册得知,cc2530的P0口作为普通IO,其中断触发方式好像只有边沿触发方式。

IEN1.P0IE定位到某个端口,P0IEN定位到该端口的具体引脚位。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: