Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lesson 01 set alt5 for gpio 14/15 #251

Closed
remi-boivin opened this issue Jun 2, 2022 · 4 comments
Closed

lesson 01 set alt5 for gpio 14/15 #251

remi-boivin opened this issue Jun 2, 2022 · 4 comments

Comments

@remi-boivin
Copy link

I'm currently read the first lesson and I can't understand why we use 12 and 15 to speak about 14/15 gpio

    unsigned int selector;
    selector = get32(GPFSEL1);
    selector &= ~(7<<12);                   // clean gpio14
    selector |= 2<<12;                      // set alt5 for gpio14
    selector &= ~(7<<15);                   // clean gpio15
    selector |= 2<<15;                      // set alt5 for gpio 15
    put32(GPFSEL1,selector);```
    Anyone can explain to me pls ?
@rockytriton
Copy link

for the GPFSEL1 register, bits 12-14 control gpio 14 and bits 15-17 control gpio 15. (7 << 12) is putting 111 in the bits 12-14 and &= ~ is clearing them, essentially. 2 << 12 is setting bits 12-14 as 010. Same goes for the 15-17 bits.

@remi-boivin
Copy link
Author

@rockytriton Thx for your answer. It's more clear for me. I've a last question how we choose 010 and 111 ?
According to
image
010 it's use to choose the 5th alternative function and 111 it's to choose the 3rd alternative function but according to
image
the 15th GPIO 3rd alternative function isn't RXD1. So I'm a little but confused.

for the GPFSEL1 register, bits 12-14 control gpio 14 and bits 15-17 control gpio 15. (7 << 12) is putting 111 in the bits 12-14 and &= ~ is clearing them, essentially. 2 << 12 is setting bits 12-14 as 010. Same goes for the 15-17 bits.

@rockytriton
Copy link

15th GPIO alt 5 = RXD1. From the table at the top 010 sets alt 5. The 111 is just to mask all 3 bits so we can clear them first before setting the values.

selector &= ~(7<<15);

That creates a mask with 15 to 17 bits set to 111, then ~ inverts the bits so all bits are set except for 15 to 17, then selector &= that to ensure that bits 15 to 17 are cleared (set to 0) but the remaining bits on selector are left as-is. Now that we clear those 3 bits, we can set the value to 010 by ORing it with this line:

selector |= 2<<15;

@remi-boivin
Copy link
Author

@rockytriton Okay thank you very much for your explanations :)

15th GPIO alt 5 = RXD1. From the table at the top 010 sets alt 5. The 111 is just to mask all 3 bits so we can clear them first before setting the values.

selector &= ~(7<<15);

That creates a mask with 15 to 17 bits set to 111, then ~ inverts the bits so all bits are set except for 15 to 17, then selector &= that to ensure that bits 15 to 17 are cleared (set to 0) but the remaining bits on selector are left as-is. Now that we clear those 3 bits, we can set the value to 010 by ORing it with this line:

selector |= 2<<15;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants