This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to use the GPIO OUTSET register and OUTCLR register in a right way ?

I have a question about using the GPIOs,I found that I can set a ‘1’ at the same bit position of OUTSET register and OUTCLR register. But which one is effective ?

  • The -SET and -CLR pattern is described in section 9.1.2 of the nRF51 Reference Manual:

    Registers with multiple single-bit bit-fields may implement the “set and clear” pattern. This pattern enables firmware to set and clear individual bits in a register without having to perform a read-modify-write operation on the main register. This pattern is implemented using three consecutive addresses in the register map where the main register is followed by a dedicated SET and CLR register in that order. The SET register is used to set individual bits in the main register while the CLR register is used to clear individual bits in the main register. Writing a ‘1’ to a bit in the SET or CLR register will set or clear the same bit in the main register respectively. Reading the SET or CLR registers returns the value of the main register.

    If you write 1 to a bit in both the -SET and -CLR register, the outcome will hence depend on the sequence, and the last action is the determining one.

Related