Difference between revisions of "RPI SPI8"

From Land Boards Wiki
Jump to navigation Jump to search
Line 79: Line 79:
 
== Schematics ==
 
== Schematics ==
  
* [http://land-boards.com/RPI_SPI8/RPI_SPI8_Schematic_Rev2.pdf Rev 2 Schematic]
+
* [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 Rev 3 Schematic]
+
* [http://land-boards.com/RPI_SPI8/RPI_SPI8_Schematic_Rev3.pdf RPI_SPI8 Rev 3 Schematic]
  
 
== Programming ==
 
== Programming ==

Revision as of 18:03, 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

Rev 3

  • Test Block changed marking to "TEST"
  • Added "REV 3" to rear silkscreem

Rev 2

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

Rev 1

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

REV1 RWK.PNG

Assembly Sheet

RPI-SPI8 Assembly Sheet - Rev 1