0
\$\begingroup\$

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.

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

1 Answer 1

2
\$\begingroup\$

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.

\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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