Close

Raspberry Pi GPIO Emulation

A project log for Not Quite Useless Raspberry Pi Replacement

Make a Raspberry Pi replacement using a Cypress Semiconductor Programmable System on a Chip (PSOC 5)

land-boardscomland-boards.com 10/10/2019 at 00:490 Comments

Let's take a look at using the PSoC pins that connect to the Raspberry Pi connector (RPi connector pinout). In this case, we will attach one of our cards, the RPP-UIO-16 card. It provides header pins for each I/O pin on the Raspberry Pi 40 pin header. It also has an EEPROM for the ID of the card. There's also 16-bits of 3.3V to 5V bidirectional level shifters on the card to allow for 5V I/O.

Emulation of the Raspberry Pi GPIO is pretty easy in the PSoC.

First, drop the Raspberry Pi pins onto a schematic sheet in PSoC Creator. They are software controlled pins so they don't need anything other than an input. I'm using the Broadcom BCM pin numbering order to make porting Raspberry Pi code simpler/compatible.

Here's the I/O pins on the schematic along with an example pin configuration.

The pins are directly accessed with IO_XX_Read( ) and IO_XX_Write( ) functions which PSoC Creator makes based on the pin names IO_XX. They look like this (for write to IO17).

The pin list is an enumerated type in C. This sets a numerical index for the pins which the switch case (earlier) uses to decide which pin can be used. It's also passed to the routine as bcmPinNum.  I don't know if the compiler will optimize the code (the correct case statement is a good thing for the compiler to optimize and using integers helps) but using an enum makes it possible to have a faster seek algorithm than a long series of if-then statement.

The calling routine from main( ) or whatever routine, calls them like this:

To access the ports, first set all of the Raspberry Pi pins as outputs and write out a zero.

Then call the blink routine for each Raspberry Pi pin:

The blink routine looks like:

Discussions