User avatar
SavagePi
Posts: 42
Joined: Mon Mar 31, 2014 7:34 pm
Location: Staffordshire, England

GPIO port 'Bit' order

Mon Aug 18, 2014 8:00 pm

I'm writing a 'standard' function for use in all my projects that access the GPIO ports, and I was wondering...

Is there, or has there ever been a 'standardised' bit order for the GPIO ports? As an example, the Gertboard uses the following ports for bits '0' through to bit '11' respectively...

GPIO25, 24, 23, 22, 27, 18, 17, 11, 10, 9, 8, 7

Given that the RPi B+ is now available (I have all three versions now!) with even more GPIO ports available, is there actually a 'definitive' order for the ports themselves.

Historically, I/O port bits have always been ordered D0-D7 (8-bits) or D0-D15 (16-bits) etc, but the RPi seems to have no assigned order, particularly since the GPIO ports are not completely sequential.
Electronics... It's what I do!

User avatar
joan
Posts: 14022
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: GPIO port 'Bit' order

Mon Aug 18, 2014 8:05 pm

On all revisions of the Pi gpio n is set/cleared by setting/clearing bit n of a 32 bit word. Why not use that scheme?

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

Re: GPIO port 'Bit' order

Mon Aug 18, 2014 8:05 pm

You must unlearn what you have learned about I/O ports. Every pin has it's own functions which can be defined from software. This isn't a straight 8-bit I/O port.

User avatar
SavagePi
Posts: 42
Joined: Mon Mar 31, 2014 7:34 pm
Location: Staffordshire, England

Re: GPIO port 'Bit' order

Mon Aug 18, 2014 8:22 pm

joan & rpdom.

I understand both of your replies and I know how to turn stuff off and on.

rpdom: I'm not looking to 'unlearn' everything I've ever learned. Even in the standard world of 8-bit or 16-bit world of interfacing, every 'bit' has always had its own designated function depending what it's been connected to - either an input or an output.

All I'm saying is that nobody (not even the designers) seems to have assigned a designated order to the GPIO ports.

It makes no difference to me. I can assign the individual ports to any function I like and control them however I want. I was just wondering if there was actually any 'standardised' bit order.
Electronics... It's what I do!

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 11859
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: GPIO port 'Bit' order

Mon Aug 18, 2014 8:47 pm

Memory mapping of the GPIO registers is fully documented, in here: http://www.raspberrypi.org/documentatio ... /README.md

from page 90 onwards.

User avatar
jojopi
Posts: 3078
Joined: Tue Oct 11, 2011 8:38 pm

Re: GPIO port 'Bit' order

Mon Aug 18, 2014 8:55 pm

In the original schematics, the seven pins with the least-useful special functions were named GPIO_GEN0…6, and the first published pinout added GPIO_GCLK0 (BCM2835 GPIO4) as GEN7. So there was a semi-official ordering for the first eight signals, and this survives as the default numbering in WiringPi.

It is very questionable whether you want to use that ordering for a parallel bus in any particular project, however. GEN2 changes between Rev1 and Rev2, and GEN1 may be better avoided on B+ where it is the only pin that can be assigned as I²S PCM_CLK.

Probably you should start by ruling out any pins you have other uses for, then assign the remainder to your bus in some logical order. If you are not making a PCB it may make more sense to assign them in order of physical position to make wiring easier. Otherwise you may prefer to assign them in ascending or descending GPIO order.

Either way, it is best to use the Broadcom GPIO numbers internally, but make them configurable so that you can always change them in future if needed.

Return to “Automation, sensing and robotics”