SPI

Questions on control of serial busses
Post Reply
kochevnik
Posts: 24
Joined: Sat Jun 15, 2013 3:27 pm

SPI

Post by kochevnik » Fri Jul 26, 2013 2:55 am

SPI Testing - Hooked up one basic chip to another one. I wired :

pin1 on BChip Master to pin 1 on BChip Slave
pin2 on BChip Master to pin 2 on BChip Slave
pin3 on BChip Master to pin 3 on BChip Slave
pin9 on BChip Master to pin 9 on BChip Slave

No resistors between them - this a mistake ?

My master and slave code is below. I start the slave and let it loop around waiting for something/anything from the master.
Don't get any response from the slave of course :) - so what's wrong with my code ?

If it makes any difference, I also tried with no CS pin, i.e. SPIOUT(-1,3,2,0,1,outstring) and SPIIN (-1,2,3,1,0,-1,outstring,1,instring)

MASTER CODE

Code: Select all

// DONT NEED CS/SS PIN IF ONLY ONE SLAVE ?
// MISO  pin 1     input
// MOSI  pin 2     output
// CLK   pin 3     output
// SS    pin 9     output

#include <SPI.bas>

input(1)
output(2)
output(3)
output(9)

LO = 0
HI = -1
out(9) = HI
out(9) = LO

// SUB SPIOUT (CSpin, CLKpin, OUTpin, LSBfirst, OUTcnt, BYREF OUTlist AS STRING)

DIM outstring(10) as STRING
outstring(0) = chr(50)

print "BEGIN"
	print x, outstring(x)
	SPIOUT(9,3,2,0,1,outstring)
print "END"

SLAVE CODE

Code: Select all

// MISO  pin 1     output
// MOSI  pin 2     input
// CLK   pin 3     input
// SS    pin 9     input

// SUB SPIIN (CSpin, INpin, CLKpin, OUTpin, LSBfirst, OUTcnt, BYREF OUTlist as STRING, INcnt, BYREF INlist as STRING)

#include <SPI.bas>

output(1)
input(2)
input(3)
input(9)

DIM instring(10) as STRING
DIM outstring(10) as STRING
 
print "BEGIN"

do

	SPIIN (9,2,3,1,0,-1,outstring,1,instring)
	if instring(0) <> 255 then goto stop1

loop

stop1:
print "instring(0) ", instring(0)

print "END"



basicchip
Posts: 845
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: SPI

Post by basicchip » Fri Jul 26, 2013 2:05 pm

No resistors needed.

SPIIN and SPIOUT are bit banged routines that are for the master side.

If you want the slave to also be bit banged, you will have to write your own routine, and most likely have to slow down the master side. The better way to go is to use the SPI or SSP hardware.

kochevnik
Posts: 24
Joined: Sat Jun 15, 2013 3:27 pm

Re: SPI

Post by kochevnik » Sat Jul 27, 2013 1:43 am

bilge

Gerrym
Posts: 1
Joined: Mon Jan 20, 2014 6:30 pm

Re: SPI

Post by Gerrym » Wed Jan 22, 2014 7:00 pm

hello Forum from Gerrym I am new to the Forium and wish to know if someone out there has a short routine for the three wire SPI interface as applied on the PRO Start Board. I would very much appreciate it if you do.
A web link would suffice if that is available. Thanks to you programming Gurus!

basicchip
Posts: 845
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

Re: SPI

Post by basicchip » Thu Jan 23, 2014 11:42 pm

Actually there are a couple examples of SPI using bit-banged routines in the help files. The advantage is you can use any 2/3/4 pins, but it is of course slower.

The SPI is actually pretty easy to use in the NXP parts, the NXP user manuals describes the steps. The most complex thing on some of the newer parts is the clock controls, to save power most of those clocks are turned off at RESET.

Post Reply