Reputation: 11
Im working on an Raspberry Pi Assembly Project with some LED's and Input Button. At the moment I have a blinking LED and a Button to turn on another LED. Now i want to set up another LED and I'm stuck on something I'm doing wrong or don't quite understand.
So if I have more then one LED's in one GPFSEL, I need to set them in one line of Code so they dont overwrite each other. For example:
GPIO Port 21 is FSEL21 = Bit 5 - 3
GPIO Port 27 is FSEL27 = Bit 23 - 21
To set them to Output I need to set the least significant bit to 1. These are: 0x08 and 0x200000 in Hex.
If I do it in two lines of code, like:
ldr register,=0x08
str register,[base,#GPFSEL2]
ldr register,=0x200000
str register,[base,#GPFSEL2]
It doesnt work.
So I did it in one line of Code and this worked:
ldr register,=0x200008
str register,[base,#GPFSEL2]
The problem I have now is to set the GPFSEL1 because it has one Output and one Input. The Documentary says i have to set 000 for an input.
So I have:
GPIO Port 19 = Output is FSEL19 = Bit 29 - 27
GPIO Port 17 = Input Button is FSEL17 = Bit 23-21
GPIO 19 = 0x8000000
GPIO Port 17, the documentary says i have to set the bits to 000. And a tutorial I'm reading sets the mask to 0xFF1FFFFF which is 11111111000111111111111111111111 in Binary.
Now i don't understand how I cant set them together. And do I have to set the input? Shouldn't it be 000 anyway if I dont set anything? I tried to not set anything in input and it worked as input but the blinking LED's got really slow without any other change in the code. I hope you can tell me what's the correct way to set this bits.
Thank you for your help!
Upvotes: 1
Views: 1042
Reputation: 6984
you have to make sure to touch only these bits which you are interested in. Changing other ones will affect function of unrelated pins.
accordingly BCM datasheet, you want to set these bits to 0b001 (GPIO output).
To set the function of the output pins, you can use
ldr r0, [base,#GPFSEL2]
bic r0, #(7 << 3)
bic r0, #(7 << 21)
orr r0, #(1 << 3)
orr r0, #(1 << 21)
str r0, [base,#GPFSEL2]
Ditto for input, but you can omit the orr
there.
Upvotes: 1