9

I am just getting started with using the GPIO on the Raspberry Pi for various projects. There are many breakout boards for the RPi and many of those have pins in order to stack boards on top of each other. It seems like the GPIO pins just go straight through and all the boards have the same pins in common. To me this means that all the boards in a stack receive the exact same signals from the RPi and should behave accordingly. This seems like this can produce a lot of errors with commands meant for one board affecting the way another board operates, but apparently this does not happen.

So how does the Raspberry Pi know which board is getting which particular commands? Is there some sort of initialization command that only a particular board recognizes and then starts accepting the rest of the commands?

cspirou
  • 387
  • 1
  • 5
  • 11
  • This is also something I see with stackable arduino shields and other various computing platforms. – cspirou Mar 15 '15 at 14:14
  • The answer I'm afraid is there is no standard way for one board to detect another and reconfigure itself. You will have to examine the details of each board before purchase and make your own determination of there ability to work with one another. – joan Mar 15 '15 at 15:38

3 Answers3

6

Computers use a system called busing to connect multiple peripheral devices to the CPU via the same set of wires. I2C and SPI are examples of busing systems used with the pi GPIO pins, which enable multiple devices on the same physical pins (managed by the internal bus) but using different addresses. Addressing is an abstraction created by the bus system protocol. It is a little bit like how you can have multiple networked applications using the same physical connection to the internet, all running simultaneously.

For example, looking at the RTC Pi Plus, one of the stackable boards from your example link:

enter image description here

Notice on the near side the five connections in a box. These correspond to pins on the other side. They're labelled:

  • 5V = Power, sharable with other devices.
  • GND = Ground, also common.
  • SDA and SCL = I2C bus pins; on the pi that's pins 3 and 5. You can have quite a number of devices on the I2C bus all using these same two pins for communication.
  • SQW = I believe this stands for "square wave" and maybe one of our more electronically knowledgeable members will leave a nice comment explaining its purpose.

In other words, most of the pins aren't used by this board at all. They are just there to allow for stacking. The ones that it does use are all (or mostly, still don't know about SQW) sharable simultaneously with other devices.

The real limit to stacking this way is going to be the amount of power that can be supplied vs. what is consumed, not the number of pins involved. Maybe it would become a limitation if you included additional power supplies, but I think before that you'd have to move the stack outside and start using a ladder to work on it. ;)

goldilocks
  • 58,859
  • 17
  • 112
  • 227
3

You can only have one HAT board so there is no such issue. There are some boards where you can connect more than one but those are not HAT boards.

salmon
  • 126
  • 3
  • 1
    HATs might not be the correct thing to say but I am talking about boards that connect to the GPIO pins. The following site shows tall stacks of such boards.

    https://www.abelectronics.co.uk/

    I can modify the question to remove 'HATs'

    – cspirou Mar 15 '15 at 14:34
1

So how does the Raspberry Pi know which board is getting which particular commands?

The Pi cannot know. You have to make sure.

The thing is, if you connect multiple extension boards, you will have to take care that signals lines are either not used more than once or implement a busing scheme that can work with multiple devices sharing some lines (as @goldilocks already suggested). To get a feeling how this could be done, I would recommend to read up on the old ISA bus. Something that could be implemented using GPIO as data and address lines (and if one is up for the pain).

Is there some sort of initialization command that only a particular board recognizes and then starts accepting the rest of the commands?

While HATs are out of the question, the identification scheme they use is worth a look. Note that there are no stacked HATs* (per Raspberry Pi Blog: Stackable HATs featured in the specification discussion – but eventually it was thrown out due to the large increase in complexity of autoconfig and potential for user error.). So at any given time only one HAT will be connected, have its EEPROM read out, and made its information available at the device tree.


* It is possible to make stackable hats if they are of the same type and thus do not require multiple and differing identification, e.g. the Adafruit 16-Channel PWM/Servo HAT for Raspberry Pi.
Ghanima
  • 15,855
  • 15
  • 61
  • 119