Most of the interface devices have various flag bits (that can also raise interrupts if that functionality is provided) used to check the status of the device/operation.
Usually they are cleared by writing a '1' to said bit.
Just some questions regarding this ...
Why are they cleared by writing a 1? I mean if the flag is already set to 1 by the device, won't it make sense to clear it by writing a 0 to it?
Lets say i have a 8 bit status register with bits distributed as (picked from datasheet of NRF24L01+)
If bit 5 (TX_DS) gets set (ie. turns to 1) and I want to clear it by writing 1 to it, what value do I write to the register.
Answer
No, because then you could possibly clear other bits you didn't intend to by accident. It's a little hard to verbalize, but it is very easy to write a 0 simply by, well, writing a 0. You must deliberately choose to write a 1.
Since every position expects a 1 in order to clear it, write a 1 only to bit 5:
STATUS = _BV(TX_DS);
No comments:
Post a Comment