# Clock gating on Tiva Launchpad

I am working on a Tiva launchpad board and want to use the GPIO. I have successfully enabled the clock on PORTF using this line of code:

SYSCTL_RCGCGPIO_R = 0x20U;


So I tried changing the above line to the one shown below:

SYSCTL_RCGCGPIO_R |= (5 << 1U);


This did not work. Will someone explain the difference between the two.

• This is all standard C syntax, which is well documented all over the internet. What exactly is confusing to you? – Elliot Alderson Mar 23 at 14:43
• @ElliotAlderson the first line works. If replace it with the second it fails. – Rufusy Mar 25 at 8:08

Lets convert all of your integer values to binary for easier comparison.

    0x20 -> 0b00100000
5    -> 0b00000101
(5 << 1) -> 0b00001010


I think you can already see the problem.

If, however, you did (1 << 5) instead, you'd have:

    0x20 -> 0b00100000
1    -> 0b00000001
(1 << 5) -> 0b00100000


So, to sum it up, you need to shift 1 left by 5 bits, not shift 5 left by 1 bit.