Notes of PhiL    About    Categories    Tags    Archive    Feed    GitHub Repo

Bit Manipulating in Registers

I broke my LaunchPad, and now I’m waiting for a new LaunchPad to deliver. In the mean time, I would like to take time to provide a small tip. I’ll take Run Mode Clock Gating Control register (RCGCGPIO) in the Tiva C-Series as an example for this post.

According to the data sheet, this register looks like:


I choose clock gating control because we must unlock the clock before making any change in the corresponding port. Bit field [31:6] is reserved, which means we would be happier not to touch them. We can only manipulate [5:0] corresponding to [PortF:PortA]. So, in order to “unlock” the clock of a port (i.e. port B) and not to mess with others:

  1. Write:

  2. Convert binary to hex:
    B000010 = 0x02

  3. Code:
    SYSCTL_RCGC2_R |= 0x02;

There are two ways to manipulate a bit in this course:

Using this strategy, we can unlock more clock since “1″ stands for “enable” and “0″ stands for “disable”.

That’s all I got. I hope this helped.