bahjat
Posts: 3
Joined: Sun Jul 02, 2017 1:14 pm

Accessing GPIO registers and altering their values

Sun Jul 02, 2017 3:25 pm

Hi guys, i'm new to this forum and the Embedded world in general but really want to learn!

My question is regarding the GPIO registers in the raspberry PI. How do i find out which register represent the different GPIO pins, and would it be as simple as changing a simple bit in the specific register to turn the GPIO high? Or is more involved

I've read the BCM2385 ARM Peripherals manual and don't really understand what it's telling me to do or the information it contains.

I've used the WiringPI.h functions to turn GPIO PIN 8 high so i can turn the LED on but ideally i don't want to rely on other peoples functions and want to write everything myself (that's how i know i would've learnt it). I decided to reverse engineer this as well, trying to look at the source code for this library but it's just a header file and no "actual" c code is in it (like the setup function). Any ideas where the setup function .c file is located?

Apologies for rambling, i'm really excited about this new project


User avatar
rpdom
Posts: 14987
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Accessing GPIO registers and altering their values

Sun Jul 02, 2017 8:46 pm


bahjat
Posts: 3
Joined: Sun Jul 02, 2017 1:14 pm

Re: Accessing GPIO registers and altering their values

Tue Jul 04, 2017 9:24 am


Thanks all for the reply!

I've made some progress in my understanding of how GPIO pins work in the raspberry pi 3, however i am having significant issue reading the registers that i want to read. I am using the devmem2 command to read the register. The command i enter and the reply i get are shown below. I can't make heads or tail of this output because the register according to the manual is supposed to be 32 bits long!

Code: Select all

devmem2 0x7e200034
/dev/mem opened 
Memory mapped at address 0x76f2f000
Value at address 0x2116026420 (0x76f2f034):0x0

User avatar
rpdom
Posts: 14987
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Accessing GPIO registers and altering their values

Tue Jul 04, 2017 1:51 pm

That output is slightly misleading. It say that the address is 0x2116026420, but that is the decimal value of the address. It should show 0x7e200034. The contents of the address are 0x76f2f034 which is a 32 bit value.

boyoh
Posts: 1316
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: Accessing GPIO registers and altering their values

Tue Jul 04, 2017 2:48 pm

You are new to the forum, but are you new to understanding digital electronics.
It will give the forum a better understanding of what you know, Some times
It can be difficult to give you the answers in a way you can understanding,
Do you under stand what state the GPIO is in if not Pulled up or not Pulled Down
States like you must under stand , Code is not the answer to everything
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

bahjat
Posts: 3
Joined: Sun Jul 02, 2017 1:14 pm

Re: Accessing GPIO registers and altering their values

Tue Jul 04, 2017 7:47 pm

rpdom wrote:That output is slightly misleading. It say that the address is 0x2116026420, but that is the decimal value of the address. It should show 0x7e200034. The contents of the address are 0x76f2f034 which is a 32 bit value.
Yep that's cleared up my misunderstanding, thanks a lot for your help!
If i could pick your brain with another (silly) question, according to the data sheet for the processor there are 54 GPIO pins. However according according to the GPIO pin output for Raspberry Pi 3 Model b (J8 Header) I only have 28 GPIO pins that i am physically able to use. I understand that it is normal for the processor manufacturer to give you a lot more stuff then then the hardware engineer can use. My question is how do i match up what it says on the datasheet with real life? Will GPIO pin 8's register values stated in the processor manual still be valid for the practical raspberry pi?
boyoh wrote:You are new to the forum, but are you new to understanding digital electronics.
It will give the forum a better understanding of what you know, Some times
It can be difficult to give you the answers in a way you can understanding,
Do you under stand what state the GPIO is in if not Pulled up or not Pulled Down
States like you must under stand , Code is not the answer to everything
I'd call myself a relative newbie to the entire field of embedded systems, i have a basic understanding of what occurs but it's nowhere close to where i want to be! If i don't understand a technical term you guys use i'll google it and try and learn the concept it represents. I am always looking to learn new stuff :)

User avatar
rpdom
Posts: 14987
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Accessing GPIO registers and altering their values

Tue Jul 04, 2017 8:23 pm

bahjat wrote:according to the data sheet for the processor there are 54 GPIO pins. However according according to the GPIO pin output for Raspberry Pi 3 Model b (J8 Header) I only have 28 GPIO pins that i am physically able to use. I understand that it is normal for the processor manufacturer to give you a lot more stuff then then the hardware engineer can use. My question is how do i match up what it says on the datasheet with real life? Will GPIO pin 8's register values stated in the processor manual still be valid for the practical raspberry pi?
The datasheet uses the internal Broadcom (BCM) numbering system. If you stick to that numbering system you will be able to match the GPIOs to the registers. A handy pinout diagram giving the capabilities of each pin in various numbering schemes is available at http://pinout.xyz

For example, physical pin 7 is BCM GPIO 4, physical pin 8 is BCM GPIO 14 and that is how it will be referred to in the registers.

Return to “Beginners”