Reset of interrupt register

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Reset of interrupt register

1,119 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gillys on Fri May 11 17:35:10 MST 2012
[SIZE=2]Hello,

is there a difference between
LPC_TIM0->IR = (0x1 << 1); and
LPC_TIM0->IR |= (0x1 << 1);[/SIZE]

The last example is not working in my case, however I don't understand why.

Quote from the datasheet:
The Interrupt Register consists of 4 bits for the match interrupts and 4 bits for the capture interrupts. If an interrupt is generated then the corresponding bit in the IR will be high. Otherwise, the bit will be low. Writing a logic one to the corresponding IR bit will reset the interrupt. Writing a zero has no effect. The act of clearing an interrupt for a timer match also clears any corresponding DMA request.
0 项奖励
回复
6 回复数

1,110 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by stalisman on Tue May 15 01:28:44 MST 2012
Hi Leji,

thanks for the explanation.   I get it now.

It is because it is a Register that we are writing to and not a simple Memory Location that the 'simple' C Source is dangerous.

I find that troublesome because Masked_Access is designed to get around these read/modify/write aspects with GPIO, so why haven't they ensured that the 'same' is safe for registers?  ie being able to OR in a single bit.

I don't know this chip well enough yet, but I'll certainly keep an eye out in future.

Cheers

Stali
0 项奖励
回复

1,110 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Leji on Mon May 14 07:17:49 MST 2012
Say you only want to reset channel 1, if IR contains 0b1111 and you do :
IR |= (1<<1)
then you will actually reset all 4 channels, so it's the same as doing:
tmpReg = IR; //tmpReg = 0b1111
tmpReg |= (1<<1); //tmpReg = 0b1111
IR = tmpReg; //we're now resetting all channels
Using IR = 1<<1; is therefore safer
0 项奖励
回复

1,110 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by stalisman on Mon May 14 02:11:26 MST 2012

Quote: cfb
. If IR is non-zero then the second statement will be writing 1's to other bits as well.



I don't quite follow that .. could you elaborate a little?

cheers
0 项奖励
回复

1,110 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Sat May 12 04:44:59 MST 2012
Actually the problem with |= is that it does reset the other interrupt flags. Use '='.

Also, there is no difference between 0x1 and 1. Keep the things simple:
LPC_TIM0->IR = 1 << MY_CHANNEL;
0 项奖励
回复

1,110 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gillys on Fri May 11 19:13:22 MST 2012
Thanks,

for me that mean that [SIZE=2]LPC_TIM0->IR |= (0x1 << 1); is not reseting the flag.
[/SIZE]
0 项奖励
回复

1,110 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by cfb on Fri May 11 17:58:25 MST 2012

Quote: gillys
[SIZE=2]Hello,[/SIZE]

[SIZE=2]is there a difference between[/SIZE]
[SIZE=2]LPC_TIM0->IR = (0x1 << 1); and[/SIZE]
[SIZE=2]LPC_TIM0->IR |= (0x1 << 1);[/SIZE]



The first statement only writes to IR. The second statement reads the IR before writing to it but that should be OK as it is a R/W register.

However, what is written by the second statement depends on the current value of IR. If it is zero or already 0x10 then the end result should be the same. If IR is non-zero then the second statement will be writing 1's to other bits as well.
0 项奖励
回复