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:


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


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

  • \$\begingroup\$ This is all standard C syntax, which is well documented all over the internet. What exactly is confusing to you? \$\endgroup\$ – Elliot Alderson Mar 23 at 14:43
  • \$\begingroup\$ @ElliotAlderson the first line works. If replace it with the second it fails. \$\endgroup\$ – 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.


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.