Difference between revisions of "RPI SPI8"

From Land Boards Wiki
Jump to navigation Jump to search
 
(117 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[File:RPI_SPI8_720px.png]]
+
[[File:tindie-mediums.png|link=https://www.tindie.com/products/26432/]]
 +
 
 +
[[File:RPI_SPI8_P1892-720px.jpg]]
  
 
== 8-Channel SPI Bus Multiplexer for the Raspberry Pi ==
 
== 8-Channel SPI Bus Multiplexer for the Raspberry Pi ==
  
* 8 channels
+
* 8 SPI channels
* Supports SPI star topology
 
** MISO from all slaves are wired together
 
 
* Connects to the SPI pins on the Raspberry Pi
 
* Connects to the SPI pins on the Raspberry Pi
 +
* Supports SPI star or daisy-chain topologies - or a mix of both
 +
** Daisy chain often used to get around the single Chip Select limitation (which this card addresses)
 
* 3.3V
 
* 3.3V
 
** 50 mA limit from Raspberry Pi
 
** 50 mA limit from Raspberry Pi
 +
** Card max current = 0.16 mA
  
 
=== SPI Star Topology ===
 
=== SPI Star Topology ===
 +
 +
* MISO from all slaves are wired together
 +
* MOSI, SCLK is sent out to all ports
 +
* SS (Slave Select) is separate for each of the 7 ports
 +
* A0-A2 lines from Raspberry Pi control the port number
  
 
[[File:SPI_Star_Topology.png]]
 
[[File:SPI_Star_Topology.png]]
Line 18: Line 26:
 
<pre>In Star topology all the signals are split and routed to each slave in parallel, except chip select. Multiple chip select are used to select individual slave devices. More devices support this mode than daisy-chain.</pre>
 
<pre>In Star topology all the signals are split and routed to each slave in parallel, except chip select. Multiple chip select are used to select individual slave devices. More devices support this mode than daisy-chain.</pre>
  
An example of a part ([[http://ww1.microchip.com/downloads/en/DeviceDoc/22060b.pdf MCP4231 Digital Pot]]) which supports this mode (p 31):
+
An example of a part ([http://ww1.microchip.com/downloads/en/DeviceDoc/22060b.pdf MCP4231 Digital Pot]) which supports this mode (p 31):
  
 
[[File:SPI_DO_Open_Drain.PNG]]
 
[[File:SPI_DO_Open_Drain.PNG]]
 +
 +
=== SPI Daisy-Chain Topology ===
 +
 +
Daisy-chain mode could also be used via external wiring.
 +
 +
* MOSI / MISO from all slaves are connected in series
 +
* SCLK is sent out to all ports
 +
* Individual (Slave Select) is separate for each daisy-chain
 +
* A0-A2 lines from Raspberry Pi control the port number
 +
 +
[[file:SPI_Daisy-Chain_Topology.png]]
  
 
== Connectors ==
 
== Connectors ==
 +
 +
[[file:RPI_SPI8_CAD.PNG]]
 +
 +
=== SPI Connectors ===
 +
 +
* Four of 2x6 right angle headers
 +
** J3 = Ports 0,1
 +
** J1 = Ports 4,5
 +
** J4 = Ports 2,3
 +
** J2 = Ports 0,1
 +
* Pinouts (silkscreen marking)
 +
# SPICE0 Channels[0-7] (marked )
 +
# SPIMOSI (marked MO)
 +
# SPIMISO (marked MI)
 +
# SPISCK (marked CK)
 +
# VCC (3.3V from Raspberry Pi)  (marked +V)
 +
# GND (marked GND)
  
 
=== 40-Pin Raspberry Pi Connector ===
 
=== 40-Pin Raspberry Pi Connector ===
  
* SPIMISO - GPIO Pin 21
+
* Standard Raspberry Pi 40-pin connector
* SPIMOSI - GPIO Pin 19
+
* SPI connections
* SPISCK - GPIO Pin 23
+
** SPIMISO - GPIO IO_9 - Pin 21
* SPICE0 - GPIO Pin 24
+
** SPIMOSI - GPIO IO_10 - Pin 19
 +
** SPISCK - GPIO IO_11 - Pin 23
 +
** SPICE0 - GPIO IO_8 - Pin 24
 
* Three GPIO pins select SPI channel
 
* Three GPIO pins select SPI channel
** GPIO Pin 22 - A0
+
** A0 - GPIO IO_22 - Pin 15
** GPIO Pin 27 - A1
+
** A1 - GPIO IO_27 - Pin 13
** GPIO Pin 17 - A2
+
** A2 - GPIO IO_17 - Pin 11
  
 
* BCM pin numbers
 
* BCM pin numbers
Line 39: Line 77:
 
[[File:RPI_40Pin_Conn.PNG]]
 
[[File:RPI_40Pin_Conn.PNG]]
  
* PSOC5 to BCM mapping
+
== Schematics ==
 +
 
 +
* [http://land-boards.com/RPI_SPI8/RPI_SPI8_Schematic_Rev2.pdf RPI_SPI8 Rev 2 Schematic]
 +
* [http://land-boards.com/RPI_SPI8/RPI_SPI8_Schematic_Rev3.pdf RPI_SPI8 Rev 3 Schematic]
 +
** Rev 3 is same as Rev 2 (board has additional silkscreen minor updates)
 +
 
 +
== Programming ==
 +
 
 +
=== Set the RPI_SPI8 mux channel number ===
 +
 
 +
* A0 - GPIO IO_22 - Pin 15
 +
* A1 - GPIO IO_27 - Pin 13
 +
* A2 - GPIO IO_17 - Pin 11
 +
<PRE>
 +
import RPi.GPIO  as  GPIO
 +
 
 +
USING_RPI_SPI8_CARD = True
  
[[File:RPI_PSOC5_PSOC_TO_BCM.png]]
+
if USING_RPI_SPI8_CARD:
 +
A0Pin = 15
 +
A1Pin = 13
 +
A2Pin = 11
 +
GPIO.setmode(GPIO.BOARD) # Set the board mode  to numbers pins by physical location
 +
GPIO.setup(A0Pin, GPIO.OUT) # A0
 +
GPIO.setup(A1Pin, GPIO.OUT) # A1
 +
GPIO.setup(A2Pin, GPIO.OUT) # A2
  
=== SPI Connectors ===
+
def set_RPI_SPI8_MuxPort(muxPort):
 +
if USING_RPI_SPI8_CARD:
 +
muxPort &= 0x7
 +
if (muxPort & 1) == 1:
 +
GPIO.output(A0Pin, GPIO.HIGH)
 +
else:
 +
GPIO.output(A0Pin, GPIO.LOW)
 +
if (muxPort & 2) == 2:
 +
GPIO.output(A1Pin, GPIO.HIGH)
 +
else:
 +
GPIO.output(A1Pin, GPIO.LOW)
 +
if (muxPort & 4) == 4:
 +
GPIO.output(A2Pin, GPIO.HIGH)
 +
else:
 +
GPIO.output(A2Pin, GPIO.LOW)
 +
return
 +
</PRE>
  
Four of 2x6 right angle headers
+
=== Do SPI transfer using spidev library ===
  
# SPICE0[0-7]
+
<PRE>
# SPIMOSI
+
import spidev
# SPIMISO
 
# SPISCK
 
# VCC (3.3V from Raspberry Pi)
 
# GND
 
  
== Programming ==
+
spi = spidev.SpiDev()
 +
spi.open(0, 0) # bus,device
 +
spi.max_speed_hz = 976000 # speed
  
* Set channel number on GPIO Pin 22 (A0), GPIO Pin 27 (A1), GPIO Pin 17 (A2)
+
# write_pot(potNum,input)
* Do SPI transfer
+
# potNum - 0,1 - the two pots on the SPI-POTX2 card
* [https://www.raspberrypi.org/documentation/hardware/raspberrypi/spi/README.md SPI on the Raspberry Pi]
+
# potVal = 0-127 - 7-bit pot value
* [https://pypi.org/project/spidev/ Python Spidev]
+
def write_pot(potNum,potVal):
 +
msb = (potNum & 1) << 4
 +
lsb = potVal & 0x7F
 +
spi.xfer([msb, lsb])
 +
</PRE>
  
== Application Example ==
+
=== Raspberry Pi Example Code ===
  
=== Setup ===
+
* Test [[SPI-POTX2]] Dual pot card on the Raspberry Pi using RPI_SPI8 SPI mux card
 +
* Makes triangle waves on the pot wiper pins
  
* SPI0 is disabled by default.
+
[[FILE:RPI_SPI8_P1897_720PX.jpg]]
** To enable it, use raspi-config, or ensure the line dtparam=spi=on isn't commented out in /boot/config.txt.
 
** By default it uses 2 chip select lines, but this can be reduced to 1 using dtoverlay=spi0-1cs.
 
** dtoverlay=spi0-2cs also exists, and without any parameters it is equivalent to dtparam=spi=on.
 
* Use n [[SPI-POTX2]] cards
 
* Requires n SPI cables
 
  
==== SPI Cables ====
+
=== SPI Cables ===
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 111: Line 186:
 
|-
 
|-
 
|}
 
|}
 +
 +
=== Combined Example Code ===
 +
 +
* [https://github.com/land-boards/RasPi/blob/master/RPI-SPI8/MCP4231_SPI_Test.py MCP4231_SPI_Test.py] - Our GitHub repo
 +
* Based on
 +
** [https://www.takaitra.com/spi-device-raspberry-pi/ Setup SPI on the Raspberry Pi]
 +
** [https://www.takaitra.com/mcp4151-digital-potentiometer-raspberry-pi/ MCP4151 Example Code]
 +
** [https://github.com/land-boards/RasPi/blob/master/RPI-SPI8/MCP4151_SPI_Test.py MCP4151 example code] - Stored in Github
 +
* Modified as below for MCP4351 Digital Pot
 +
** [https://github.com/land-boards/RasPi/blob/master/RPI-SPI8/MCP4231_SPI_Test.py MCP4231_SPI_Test.py]
 +
<pre>
 +
#!/usr/bin/python
 +
#
 +
# MCP4231_SPI_Test.py
 +
# Test SPI-POTX2 card on the Raspberry Pi using RPI_SPI8 SPI mux card
 +
# Makes triangle waves
 +
#
 +
# Hardware
 +
# RPI_SPI8 SPI mux card Wiki page:
 +
# http://land-boards.com/blwiki/index.php?title=RPI_SPI8
 +
# SPI-POTX2 Dual Digital Pot Wiki page:
 +
# http://land-boards.com/blwiki/index.php?title=SPI-POTX2
 +
#
 +
# Software
 +
# Original mcp4151 (digital pot) code at
 +
# https://www.takaitra.com/mcp4151-digital-potentiometer-raspberry-pi/
 +
# Setup SPI at
 +
# https://www.takaitra.com/spi-device-raspberry-pi/
 +
#
 +
# Run with -
 +
# chmod +x MCP4231_SPI_Test.py
 +
# sudo ./MCP4231_SPI_Test.py
 +
 +
import spidev
 +
import time
 +
import RPi.GPIO  as  GPIO
 +
 +
# Set the next line to False if directly connecting to Raspberry Pi SPI bus
 +
USING_RPI_SPI8_CARD = True
 +
 +
spi = spidev.SpiDev()
 +
spi.open(0, 0) # bus,device
 +
spi.max_speed_hz = 976000 # speed
 +
 +
if USING_RPI_SPI8_CARD:
 +
A0Pin = 15
 +
A1Pin = 13
 +
A2Pin = 11
 +
GPIO.setmode(GPIO.BOARD) # Set the board mode  to numbers pins by physical location
 +
GPIO.setup(A0Pin, GPIO.OUT) # A0
 +
GPIO.setup(A1Pin, GPIO.OUT) # A1
 +
GPIO.setup(A2Pin, GPIO.OUT) # A2
 +
 +
def set_RPI_SPI8_MuxPort(muxPort):
 +
if USING_RPI_SPI8_CARD:
 +
muxPort &= 0x7
 +
if (muxPort & 1) == 1:
 +
GPIO.output(A0Pin, GPIO.HIGH)
 +
else:
 +
GPIO.output(A0Pin, GPIO.LOW)
 +
if (muxPort & 2) == 2:
 +
GPIO.output(A1Pin, GPIO.HIGH)
 +
else:
 +
GPIO.output(A1Pin, GPIO.LOW)
 +
if (muxPort & 4) == 4:
 +
GPIO.output(A2Pin, GPIO.HIGH)
 +
else:
 +
GPIO.output(A2Pin, GPIO.LOW)
 +
return
 +
 +
# write_pot(potNum,input)
 +
# potNum - 0,1 - the two pots on the SPI-POTX2 card
 +
# potVal = 0-127 - 7-bit pot value
 +
def write_pot(potNum,potVal):
 +
msb = (potNum & 1) << 4
 +
lsb = potVal & 0x7F
 +
spi.xfer([msb, lsb])
 +
 +
# Test loop follows
 +
while True:
 +
for channelNum in range(0,8):
 +
set_RPI_SPI8_MuxPort(channelNum)
 +
for potNum in range(0,2):
 +
for i in range(0x00, 0x7F, 1):
 +
write_pot(potNum,i)
 +
# time.sleep(.001)
 +
for i in range(0x7F, 0x00, -1):
 +
write_pot(potNum,i)
 +
# time.sleep(.001)
 +
</pre>
 +
 +
=== Reference Docs ===
 +
 +
* [https://www.takaitra.com/spi-device-raspberry-pi/ Controlling an SPI device with the Raspberry Pi] - Takaitra.com
 +
* [https://www.takaitra.com/mcp4151-digital-potentiometer-raspberry-pi/ Controlling the MCP4151 Digital Potentiometer with the Raspberry Pi] - Takaitra.com
 +
* [https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#serial-peripheral-interface-spi SPI on the Raspberry Pi]
 +
* [https://pypi.org/project/spidev/ Python pypi spidev]
 +
* [[RaspberryPi#SPI_Interface|Land Boards SPI Reference]]
  
 
== Factory Test Procedure ==
 
== Factory Test Procedure ==
 +
 +
* Use [[RPI_PSOC5]] card to test UUT
 +
** Simpler to use than Raspberry Pi
 +
** Very short boot time
 +
** Serial connection and menu driven test
 +
 +
<video type="youtube">HCHxoRt6UVw</video>
  
 
* Verifies continuity/No shorts or opens
 
* Verifies continuity/No shorts or opens
Line 118: Line 298:
 
=== Hardware Setup ===
 
=== Hardware Setup ===
  
* [[RPI_PSOC5]] - Raspberry Pi Clone
+
[[FILE:RPI_SPI8_P1878-720PX.jpg]]
 +
 
 +
* [[RPI_PSOC5]]
 +
** Raspberry Pi CPU Clone
 
* [[LED-TEST-2]]
 
* [[LED-TEST-2]]
 +
** Uses 11 LEDs
 
* [[POWER-49MM]]
 
* [[POWER-49MM]]
 
** Distribute grounds to LEDs
 
** Distribute grounds to LEDs
* Cables 2 ports at a time
+
* Cable set
 
** 2x6 header plugs into pair of SPI ports
 
** 2x6 header plugs into pair of SPI ports
 
** 4 of 2x4 connectors attach to [[LED-TEST-2]] card
 
** 4 of 2x4 connectors attach to [[LED-TEST-2]] card
*** Power/Ground LED
+
*** (8) CE (SS)
 
*** MOSI
 
*** MOSI
 
*** MISO
 
*** MISO
*** CE (SS)
 
 
*** SCK
 
*** SCK
  
Line 137: Line 320:
 
** 115,200 baud
 
** 115,200 baud
 
** RTS/CTS flow control
 
** RTS/CTS flow control
 +
 +
[[FILE:RPI_SPI8-puTTY_setup.PNG]]
 +
 
* Hit ENTER to see menu
 
* Hit ENTER to see menu
 
<pre>
 
<pre>
Line 146: Line 332:
 
5 - Select RASPI-PLUS-GVS Card
 
5 - Select RASPI-PLUS-GVS Card
 
6 - Select RPI-I2C-HUB Card
 
6 - Select RPI-I2C-HUB Card
7 - Select RPI-SPI8 Card
+
7 - Select RPI_SPI8 Card
 
R - Read EEPROM
 
R - Read EEPROM
 
W - Write EEPROM
 
W - Write EEPROM
Line 154: Line 340:
 
? - Print this menu
 
? - Print this menu
 
</pre>
 
</pre>
* Enter 7
+
* Select RPI_SPI8 Card by entering 7[ENTER]
 
<pre>
 
<pre>
 
7
 
7
Selected RPI-SPI8 card
+
Selected RPI_SPI8 card
 
</pre>
 
</pre>
* Enter B
+
 
 +
=== Blink LEDs ===
 +
 
 +
* Enter B[ENTER]
 
<pre>
 
<pre>
b
+
B
Blinking the RPI-SPI8 Card LEDs, please wait
+
Blinking the RPI_SPI8 Card LEDs, please wait
 
</pre>
 
</pre>
* Bounces LEDs across the LEDs
+
* Bounces LEDs off across the LEDs
 
** 8 CE signals go low one at a time
 
** 8 CE signals go low one at a time
 
** MOSI, MISO, SCK cycles one on at time
 
** MOSI, MISO, SCK cycles one on at time
Line 171: Line 360:
  
 
* Runs on [[RPI_PSOC5]]
 
* Runs on [[RPI_PSOC5]]
* [https://github.com/douggilliland/RPI_PSOC5/tree/master/RPI_PSOC5_Serial_0 GitHub repo]
+
* [https://github.com/land-boards/RasPi/tree/master/RPI_PSOC5/RPI_PSOC5_CARD_TEST_STATION.cydsn GitHub repo]
 +
** [https://github.com/land-boards/RasPi/blob/master/RPI_PSOC5/RPI_PSOC5_CARD_TEST_STATION.cydsn/Test_RPI_SPI8.c Test_RPI_SPI8.c] - Bounce LED across [[LED-TEST-2]] card
 +
 
 +
== RPI_PSOC5 ==
 +
 
 +
The RPI_SPI8 can be used with the [[RPI_PSOC5]] card
 +
 
 +
[[file:SPI-POTX2_P1889_720px.jpg]]
 +
 
 +
=== SPI Schematic ===
 +
 
 +
[[file:RPI_PSOC5_SPI_LOGIC.PNG]]
 +
 
 +
=== SPI Configuration ===
 +
 
 +
* 16-bit data
 +
* MSB first
 +
* Mode = 1,1
 +
* 1 MHz
 +
 
 +
[[file:RPI_PSOC5_SPI_config.PNG]]
 +
 
 +
=== PSOC5 to BCM mapping ===
 +
 
 +
[[File:RPI_PSOC5_Pins.PNG]]
 +
 
 +
=== RPI-PSOC5 Test Station Software ===
 +
 
 +
* [https://github.com/land-boards/RasPi/tree/master/RPI_PSOC5/RPI_PSOC5_CARD_TEST_STATION.cydsn PSOC5 Software] - GitHub repo
 +
 
 +
=== RPI_PSOC5 Test Timing ===
 +
 
 +
* Card Tester
 +
* [[RPI_PSOC5]] Tester
 +
* [https://github.com/land-boards/RasPi/blob/master/RPI_PSOC5/RPI_PSOC5_RPI_SPI8_CARD_TEST.cydsn/Test_RPI_SPI8.c PSOC5 C code]
 +
* Yellow = center tap if POT0 (GND/VCC shunts installed
 +
* Cyan = Slave Select/Chip Select
 +
 
 +
[[file:SPI-POTX2-14.png]]
  
 
== Issues ==
 
== Issues ==
 +
 +
Documents the revision history of the card
 +
 +
=== Rev 3 ===
 +
 +
* Test Block changed marking on rear of card to "TEST"
 +
* Added "REV 3" to rear silkscreen
 +
* Expand SPI pin names on silkscreen
 +
 +
[[file:RPI_SPI8_CAD_Rev3.PNG]]
  
 
=== Rev 2 ===
 
=== Rev 2 ===
  
=== Rev 1 Rework ===
+
* Tested/working
 +
* Fixed wiring issue from Rev 2
 +
* Test Block marked as "TEST1"
 +
 
 +
[[file:RPI_SPI8_CAD.PNG]]
 +
 
 +
=== Rev 1 ===
  
 
* Cut etch between IC pins 5 and 6
 
* Cut etch between IC pins 5 and 6
Line 186: Line 429:
 
== Assembly Sheet ==
 
== Assembly Sheet ==
  
[[RPI-SPI8 Assembly Sheet - Rev 1]]
+
* [[RPI_SPI8 Assembly Sheet - Rev 1]]

Latest revision as of 18:40, 13 April 2022

Tindie-mediums.png

RPI SPI8 P1892-720px.jpg

8-Channel SPI Bus Multiplexer for the Raspberry Pi

  • 8 SPI channels
  • Connects to the SPI pins on the Raspberry Pi
  • Supports SPI star or daisy-chain topologies - or a mix of both
    • Daisy chain often used to get around the single Chip Select limitation (which this card addresses)
  • 3.3V
    • 50 mA limit from Raspberry Pi
    • Card max current = 0.16 mA

SPI Star Topology

  • MISO from all slaves are wired together
  • MOSI, SCLK is sent out to all ports
  • SS (Slave Select) is separate for each of the 7 ports
  • A0-A2 lines from Raspberry Pi control the port number

SPI Star Topology.png

From Practical EE: SPI Bus page:

In Star topology all the signals are split and routed to each slave in parallel, except chip select. Multiple chip select are used to select individual slave devices. More devices support this mode than daisy-chain.

An example of a part (MCP4231 Digital Pot) which supports this mode (p 31):

SPI DO Open Drain.PNG

SPI Daisy-Chain Topology

Daisy-chain mode could also be used via external wiring.

  • MOSI / MISO from all slaves are connected in series
  • SCLK is sent out to all ports
  • Individual (Slave Select) is separate for each daisy-chain
  • A0-A2 lines from Raspberry Pi control the port number

SPI Daisy-Chain Topology.png

Connectors

RPI SPI8 CAD.PNG

SPI Connectors

  • Four of 2x6 right angle headers
    • J3 = Ports 0,1
    • J1 = Ports 4,5
    • J4 = Ports 2,3
    • J2 = Ports 0,1
  • Pinouts (silkscreen marking)
  1. SPICE0 Channels[0-7] (marked )
  2. SPIMOSI (marked MO)
  3. SPIMISO (marked MI)
  4. SPISCK (marked CK)
  5. VCC (3.3V from Raspberry Pi) (marked +V)
  6. GND (marked GND)

40-Pin Raspberry Pi Connector

  • Standard Raspberry Pi 40-pin connector
  • SPI connections
    • SPIMISO - GPIO IO_9 - Pin 21
    • SPIMOSI - GPIO IO_10 - Pin 19
    • SPISCK - GPIO IO_11 - Pin 23
    • SPICE0 - GPIO IO_8 - Pin 24
  • Three GPIO pins select SPI channel
    • A0 - GPIO IO_22 - Pin 15
    • A1 - GPIO IO_27 - Pin 13
    • A2 - GPIO IO_17 - Pin 11
  • BCM pin numbers

RPI 40Pin Conn.PNG

Schematics

Programming

Set the RPI_SPI8 mux channel number

  • A0 - GPIO IO_22 - Pin 15
  • A1 - GPIO IO_27 - Pin 13
  • A2 - GPIO IO_17 - Pin 11
import RPi.GPIO  as  GPIO

USING_RPI_SPI8_CARD = True

if USING_RPI_SPI8_CARD:
	A0Pin = 15
	A1Pin = 13
	A2Pin = 11
	GPIO.setmode(GPIO.BOARD)		# Set the board mode  to numbers pins by physical location
	GPIO.setup(A0Pin, GPIO.OUT)		# A0
	GPIO.setup(A1Pin, GPIO.OUT)		# A1
	GPIO.setup(A2Pin, GPIO.OUT)		# A2

def set_RPI_SPI8_MuxPort(muxPort):
	if USING_RPI_SPI8_CARD:
		muxPort &= 0x7
		if (muxPort & 1) == 1:
			GPIO.output(A0Pin, GPIO.HIGH)
		else:
			GPIO.output(A0Pin, GPIO.LOW)
		if (muxPort & 2) == 2:
			GPIO.output(A1Pin, GPIO.HIGH)
		else:
			GPIO.output(A1Pin, GPIO.LOW)
		if (muxPort & 4) == 4:
			GPIO.output(A2Pin, GPIO.HIGH)
		else:
			GPIO.output(A2Pin, GPIO.LOW)
	return

Do SPI transfer using spidev library

import spidev

spi = spidev.SpiDev()
spi.open(0, 0)		# bus,device
spi.max_speed_hz = 976000	# speed

# write_pot(potNum,input)
#	potNum - 0,1 - the two pots on the SPI-POTX2 card
#	potVal = 0-127 - 7-bit pot value
def write_pot(potNum,potVal):
	msb = (potNum & 1) << 4
	lsb = potVal & 0x7F
	spi.xfer([msb, lsb])

Raspberry Pi Example Code

  • Test SPI-POTX2 Dual pot card on the Raspberry Pi using RPI_SPI8 SPI mux card
  • Makes triangle waves on the pot wiper pins

RPI SPI8 P1897 720PX.jpg

SPI Cables

RPI_SPI8 (Marking) RPI_SPI8 Pin SPI-POTX2 Pin SPI-POTX2 Marking
Chip En (CE) 1 5 SS
MOSI (MO) 2 4 MOSI
MISO (MI) 3 1 MISO
SPICK (CK) 4 3 SCK
Vcc (+V) 5 2 +V
GND 6 6 GND

Combined Example Code

#!/usr/bin/python
# 
# MCP4231_SPI_Test.py
#	Test SPI-POTX2 card on the Raspberry Pi using RPI_SPI8 SPI mux card
# 	Makes triangle waves
# 
# Hardware
# RPI_SPI8 SPI mux card Wiki page:
#	http://land-boards.com/blwiki/index.php?title=RPI_SPI8
# SPI-POTX2 Dual Digital Pot Wiki page:
#	http://land-boards.com/blwiki/index.php?title=SPI-POTX2
# 
# Software
# Original mcp4151 (digital pot) code at
#	https://www.takaitra.com/mcp4151-digital-potentiometer-raspberry-pi/
# Setup SPI at
#	https://www.takaitra.com/spi-device-raspberry-pi/
# 
# Run with -
# chmod +x MCP4231_SPI_Test.py
# sudo ./MCP4231_SPI_Test.py

import spidev
import time
import RPi.GPIO  as  GPIO

# Set the next line to False if directly connecting to Raspberry Pi SPI bus
USING_RPI_SPI8_CARD = True

spi = spidev.SpiDev()
spi.open(0, 0)		# bus,device
spi.max_speed_hz = 976000	# speed

if USING_RPI_SPI8_CARD:
	A0Pin = 15
	A1Pin = 13
	A2Pin = 11
	GPIO.setmode(GPIO.BOARD)		# Set the board mode  to numbers pins by physical location
	GPIO.setup(A0Pin, GPIO.OUT)		# A0
	GPIO.setup(A1Pin, GPIO.OUT)		# A1
	GPIO.setup(A2Pin, GPIO.OUT)		# A2

def set_RPI_SPI8_MuxPort(muxPort):
	if USING_RPI_SPI8_CARD:
		muxPort &= 0x7
		if (muxPort & 1) == 1:
			GPIO.output(A0Pin, GPIO.HIGH)
		else:
			GPIO.output(A0Pin, GPIO.LOW)
		if (muxPort & 2) == 2:
			GPIO.output(A1Pin, GPIO.HIGH)
		else:
			GPIO.output(A1Pin, GPIO.LOW)
		if (muxPort & 4) == 4:
			GPIO.output(A2Pin, GPIO.HIGH)
		else:
			GPIO.output(A2Pin, GPIO.LOW)
	return

# write_pot(potNum,input)
#	potNum - 0,1 - the two pots on the SPI-POTX2 card
#	potVal = 0-127 - 7-bit pot value
def write_pot(potNum,potVal):
	msb = (potNum & 1) << 4
	lsb = potVal & 0x7F
	spi.xfer([msb, lsb])

# Test loop follows
while True:
	for channelNum in range(0,8):
		set_RPI_SPI8_MuxPort(channelNum)
		for potNum in range(0,2):
			for i in range(0x00, 0x7F, 1):
				write_pot(potNum,i)
				# time.sleep(.001)
			for i in range(0x7F, 0x00, -1):
				write_pot(potNum,i)
				# time.sleep(.001)

Reference Docs

Factory Test Procedure

  • Use RPI_PSOC5 card to test UUT
    • Simpler to use than Raspberry Pi
    • Very short boot time
    • Serial connection and menu driven test

  • Verifies continuity/No shorts or opens

Hardware Setup

RPI SPI8 P1878-720PX.jpg

  • RPI_PSOC5
    • Raspberry Pi CPU Clone
  • LED-TEST-2
    • Uses 11 LEDs
  • POWER-49MM
    • Distribute grounds to LEDs
  • Cable set
    • 2x6 header plugs into pair of SPI ports
    • 4 of 2x4 connectors attach to LED-TEST-2 card
      • (8) CE (SS)
      • MOSI
      • MISO
      • SCK

Run Tests

  • Run puTTY
    • Find COM Port in Device Manager
    • 115,200 baud
    • RTS/CTS flow control

RPI SPI8-puTTY setup.PNG

  • Hit ENTER to see menu
Land Boards, LLC - RPi Card Test Station
1 - Select RPP-UIO-16 Card
2 - Select RPPSOC Card
3 - Select RASPI-PLUS-GVS-CFG Card
4 - Select RASPI-GVS Card
5 - Select RASPI-PLUS-GVS Card
6 - Select RPI-I2C-HUB Card
7 - Select RPI_SPI8 Card
R - Read EEPROM
W - Write EEPROM
B - Bounce LED across Card GPIOs
T - Test Card
D - Debug Card
? - Print this menu
  • Select RPI_SPI8 Card by entering 7[ENTER]
7
Selected RPI_SPI8 card

Blink LEDs

  • Enter B[ENTER]
B
Blinking the RPI_SPI8 Card LEDs, please wait
  • Bounces LEDs off across the LEDs
    • 8 CE signals go low one at a time
    • MOSI, MISO, SCK cycles one on at time

Test Software

RPI_PSOC5

The RPI_SPI8 can be used with the RPI_PSOC5 card

SPI-POTX2 P1889 720px.jpg

SPI Schematic

RPI PSOC5 SPI LOGIC.PNG

SPI Configuration

  • 16-bit data
  • MSB first
  • Mode = 1,1
  • 1 MHz

RPI PSOC5 SPI config.PNG

PSOC5 to BCM mapping

RPI PSOC5 Pins.PNG

RPI-PSOC5 Test Station Software

RPI_PSOC5 Test Timing

  • Card Tester
  • RPI_PSOC5 Tester
  • PSOC5 C code
  • Yellow = center tap if POT0 (GND/VCC shunts installed
  • Cyan = Slave Select/Chip Select

SPI-POTX2-14.png

Issues

Documents the revision history of the card

Rev 3

  • Test Block changed marking on rear of card to "TEST"
  • Added "REV 3" to rear silkscreen
  • Expand SPI pin names on silkscreen

RPI SPI8 CAD Rev3.PNG

Rev 2

  • Tested/working
  • Fixed wiring issue from Rev 2
  • Test Block marked as "TEST1"

RPI SPI8 CAD.PNG

Rev 1

  • Cut etch between IC pins 5 and 6
  • Add wire between IC pins 4 and 5

REV1 RWK.PNG

Assembly Sheet