Difference between revisions of "RPI SPI8"

From Land Boards Wiki
Jump to navigation Jump to search
 
(33 intermediate revisions by the same user not shown)
Line 8: Line 8:
 
* 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
 
* 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 fixes)
+
** 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 ===
Line 75: Line 76:
  
 
[[File:RPI_40Pin_Conn.PNG]]
 
[[File:RPI_40Pin_Conn.PNG]]
 +
 +
== 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 ==
 
== Programming ==
  
* Set the RPI_SPI8 mux channel number
+
=== Set the RPI_SPI8 mux channel number ===
** A0 - GPIO IO_22 - Pin 15
+
 
** A1 - GPIO IO_27 - Pin 13
+
* A0 - GPIO IO_22 - Pin 15
** A2 - GPIO IO_17 - Pin 11
+
* A1 - GPIO IO_27 - Pin 13
 +
* A2 - GPIO IO_17 - Pin 11
 
<PRE>
 
<PRE>
 +
import RPi.GPIO  as  GPIO
 +
 
USING_RPI_SPI8_CARD = True
 
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):
 
def set_RPI_SPI8_MuxPort(muxPort):
 
if USING_RPI_SPI8_CARD:
 
if USING_RPI_SPI8_CARD:
Line 101: Line 121:
 
return
 
return
 
</PRE>
 
</PRE>
* Do SPI transfer using spidev library
+
 
 +
=== Do SPI transfer using spidev library ===
 +
 
 +
<PRE>
 +
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])
 +
</PRE>
  
 
=== Raspberry Pi Example Code ===
 
=== Raspberry Pi Example Code ===
 
[[FILE:RPI_SPI8_P1897_720PX.jpg]]
 
  
 
* Test [[SPI-POTX2]] Dual pot card on the Raspberry Pi using RPI_SPI8 SPI mux card
 
* Test [[SPI-POTX2]] Dual pot card on the Raspberry Pi using RPI_SPI8 SPI mux card
 
* Makes triangle waves on the pot wiper pins
 
* Makes triangle waves on the pot wiper pins
 +
 +
[[FILE:RPI_SPI8_P1897_720PX.jpg]]
  
 
=== SPI Cables ===
 
=== SPI Cables ===
Line 150: Line 187:
 
|}
 
|}
  
=== Example Code ===
+
=== Combined Example Code ===
  
 
* [https://github.com/land-boards/RasPi/blob/master/RPI-SPI8/MCP4231_SPI_Test.py MCP4231_SPI_Test.py] - Our GitHub repo
 
* [https://github.com/land-boards/RasPi/blob/master/RPI-SPI8/MCP4231_SPI_Test.py MCP4231_SPI_Test.py] - Our GitHub repo
Line 246: Line 283:
 
* [https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#serial-peripheral-interface-spi SPI on the Raspberry Pi]
 
* [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]
 
* [https://pypi.org/project/spidev/ Python pypi spidev]
* [[RaspberryPi#SPI_Interface|Land Boards SPI]]
+
* [[RaspberryPi#SPI_Interface|Land Boards SPI Reference]]
  
== RPI_PSOC5 Test Timing ==
+
== Factory Test Procedure ==
 
 
* [[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]]
 
  
== 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>
 
<video type="youtube">HCHxoRt6UVw</video>
Line 299: 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 307: Line 340:
 
? - Print this menu
 
? - Print this menu
 
</pre>
 
</pre>
* Select RPI-SPI8 Card by entering 7[ENTER]
+
* Select RPI_SPI8 Card by entering 7[ENTER]
 
<pre>
 
<pre>
 
7
 
7
Selected RPI-SPI8 card
+
Selected RPI_SPI8 card
 
</pre>
 
</pre>
  
Line 318: Line 351:
 
<pre>
 
<pre>
 
B
 
B
Blinking the RPI-SPI8 Card LEDs, please wait
+
Blinking the RPI_SPI8 Card LEDs, please wait
 
</pre>
 
</pre>
 
* Bounces LEDs off across the LEDs
 
* Bounces LEDs off across the LEDs
Line 356: Line 389:
  
 
* [https://github.com/land-boards/RasPi/tree/master/RPI_PSOC5/RPI_PSOC5_CARD_TEST_STATION.cydsn PSOC5 Software] - GitHub repo
 
* [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 370: 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