Shift out data from one RPi to another over GPIO pins

The Raspberry Pi is a series of credit card-sized single-board computers developed in the United Kingdom by the Raspberry Pi Foundation to promote the teaching of basic computer science in schools and developing countries.

Post Reply
User avatar
/RaspberryPi
Corporate
Posts: 2449
Joined: Wed Jun 05, 2019 1:29 am

Shift out data from one RPi to another over GPIO pins

Post by /RaspberryPi »


I have two RPi from my spare parts drawer that I need to pair together so they can monitor ~26 inputs. These are older RPis so I don't have that many free GPIOs on either alone. Neither has network where they are, and I need the serial port as part of my build. So that leaves the GPIO pins, and maybe the RCA and 3.5mm audio to play with. Since I'm not working the pins in C, just python, I'm only really achieving 3Khz on each GPI. Maybe I'm doing it wrong.

So using the PINs I'm left with Serial (in use), I2C (both master), SPI (both master), PWM (don't know how), or a custom protocol. Falling into the last option, I was thinking of a custom protocol that was timing tolerant and came up with this three pin design. Maybe this is an existing protocol already, I just don't know it.

┌──────────┐ ┌─────────┐ │ master │ REQ │ slave │ │ O├───────────►│Id │ │ │ ACK │ │ │ Id│◄───────────┤O │ │ │ DATA │ │ │ Id│◄───────────┤O │ │ │ │ │ └──────────┘ └─────────┘ Initially, the master set's the REQ pin to output and ACK and DATA to input with a pull-down. The slave sets the REQ pin to input with a pull-down and the ACK and DATA to output. When the session starts REQ, ACK and DATA are all held low. When the master wants to request telemetry data from the slave, they drive REQ to ~ACK. Then the slave shifts out a bit on DATA and inverts ACK. When the master sees REQ==ACK they retrieve data from DATA and stops leaves the data wait. So the state machine is:
  • REQ == ACK - Master working, slave is waiting
  • REQ != ACK - Data is requested, master is waiting

So... will that work? Should I set the inputs as pull-up, pull-down, or float? Do I need resistors, or will the high-impedance of input mode protect things?

Or is there a better way?
UPDATE (It worked!!)
Got it working and it seems just fine. All told, 150 lines of python with a staggering throughput of (*cough*) 750 bps using an GPIO based ISR. But if I use a spinlock I can get up to 3-5 Kbps while pegging the processor. From the benchmarks I did, if I rewrite in C then I should be able to achieve something north of 700 Kbps. Faster than I2C. Even accounting for the 3-wire design, 700 Kbps on three-wires is better than 400 Kbps (I2C) on two-wires. Will take some work for me to dust off my C coding skills. There a way to get up to a few Mbps using low level GPU bit banging, but at that frequency thinks would likely fall apart fast.
submitted by /u/brianddk
[link] [comments]

Source: https://www.reddit.com/r/raspberry_pi/c ... over_gpio/
/RaspberryPi
Post Reply

Return to “Raspberry Pi Forum”