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 ...

  1. 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?

  2. Lets say i have a 8 bit status register with bits distributed as (picked from datasheet of NRF24L01+)

enter image description here

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.


1 Answer 1

  1. 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.

  2. Since every position expects a 1 in order to clear it, write a 1 only to bit 5:

    STATUS = _BV(TX_DS);
  • \$\begingroup\$ Updated the question with a clipping from the datasheet. As you see, bit 5 is indeed RW and it requires to be written with 1 to clear \$\endgroup\$
    – Ankit
    Jul 19, 2014 at 3:48
  • \$\begingroup\$ Fair enough. I will update my answer. \$\endgroup\$ Jul 19, 2014 at 3:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.