Travis_
01-14-2009, 03:11 AM
I'm trying (so far unsuccessfully) to get my PropStick USB to communicate with an SCP1000 altimeter from SparkFun (www.sparkfun.com/commerce/product_info.php?products_id=8161 (http://www.sparkfun.com/commerce/product_info.php?products_id=8161)). It uses SPI for communication.
I attached a screen capture of the SPI communication example for a simple command (get the revision id of the board). It's from page 24 of the specification document for the SCP1000 (also attached). The PST output is also attached.
Below is the code I tried using to get the RevId. Using SPI, transmit %00000000 and it should return 03hex, but it just returns %00000000
If some kind soul out there could help me find the err of my ways, I'd greatly appreciate it.
Thanks!
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
#0,MSBPRE,LSBPRE,MSBPOST,LSBPOST 'Used for SHIFTIN routines
#4,LSBFIRST,MSBFIRST 'Used for SHIFTOUT routines
High = 1
Low = 0
Out = %1
'Pin on Prop Chip for LED Indicator
PIN_LED = 15
'//Pin assignments for VTI SCP1000-D01
SPI_CSB = 0 'Chip select out connected to SCP1000 CSB pin
SPI_SCK = 3 'Clock out to SCP1000 SCK pin
SPI_MISO = 1 'Data in connected to SCP1000 MISO pin
SPI_MOSI = 2 'Data out connected to SCP1000 MOSI pin
SPI_DRDY = 4 'Data ready connected to SCP1000 DRDY pin
VAR
long DataValue, objSPI
OBJ
Debug : "FullDuplexSerial"
PUB start | data,i
'start debugger
debug.start(31,30,0,19200)
'set pin direction for LED to output
dira[PIN_LED]~~
'flash the LED to confirm the program is running
repeat 10
!outa[PIN_LED]
waitcnt(clkfreq / 2 + cnt) '0.5 seconds
'blank the screen
debug.str(string(16))
'start H48C accelerometer
debug.Str(string("Starting SPI..."))
objSPI := false
objSPI := SPI.Start
'test startup of H48C
if (objSPI)
debug.Str(string("Started Successfully!",13))
else
debug.Str(string("Failed to Start!",13))
'display data from H48C & HM55B
if (objSPI)
data := %10101010
data := GetRev
debug.str(string("GetRev should equal 03h = "))
debug.bin(data,8)
debug.str(string(13))
debug.str(string("Done."))
else
debug.str(string("Error: SPI failed to start. Terminating...",13))
PRI GetRev : datar | i
'set MOSI, CSB, SCK out
dira [ SPI_MOSI ] := Out
dira [ SPI_CSB ] := Out
dira [ SPI_SCK ] := Out
dira [ SPI_MISO ] := %0
'set CLK, MOSI low
outa [ SPI_SCK ] := Low
outa [ SPI_MOSI ] := Low
'set CSB high, then low to reset it
outa [ SPI_CSB ] := High
outa [ SPI_CSB ] := Low
repeat 8
outa [ SPI_SCK ] := High 'set CLK High
outa [ SPI_MOSI ] := %0 'transmit bin '0' on MOSI
outa [ SPI_SCK ] := Low 'set CLK low
repeat i from 7 to 0
outa [ SPI_SCK ] := High 'set CLK High
'read MISO
if ina[SPI_MISO] == 1 'read MISO
datar |= |< i ' set bit i HIGH
else
datar &= !|< i ' set bit i LOW
outa [ SPI_SCK ] := Low 'set CLK low
outa [ SPI_CSB ] := High
return datar
I attached a screen capture of the SPI communication example for a simple command (get the revision id of the board). It's from page 24 of the specification document for the SCP1000 (also attached). The PST output is also attached.
Below is the code I tried using to get the RevId. Using SPI, transmit %00000000 and it should return 03hex, but it just returns %00000000
If some kind soul out there could help me find the err of my ways, I'd greatly appreciate it.
Thanks!
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
#0,MSBPRE,LSBPRE,MSBPOST,LSBPOST 'Used for SHIFTIN routines
#4,LSBFIRST,MSBFIRST 'Used for SHIFTOUT routines
High = 1
Low = 0
Out = %1
'Pin on Prop Chip for LED Indicator
PIN_LED = 15
'//Pin assignments for VTI SCP1000-D01
SPI_CSB = 0 'Chip select out connected to SCP1000 CSB pin
SPI_SCK = 3 'Clock out to SCP1000 SCK pin
SPI_MISO = 1 'Data in connected to SCP1000 MISO pin
SPI_MOSI = 2 'Data out connected to SCP1000 MOSI pin
SPI_DRDY = 4 'Data ready connected to SCP1000 DRDY pin
VAR
long DataValue, objSPI
OBJ
Debug : "FullDuplexSerial"
PUB start | data,i
'start debugger
debug.start(31,30,0,19200)
'set pin direction for LED to output
dira[PIN_LED]~~
'flash the LED to confirm the program is running
repeat 10
!outa[PIN_LED]
waitcnt(clkfreq / 2 + cnt) '0.5 seconds
'blank the screen
debug.str(string(16))
'start H48C accelerometer
debug.Str(string("Starting SPI..."))
objSPI := false
objSPI := SPI.Start
'test startup of H48C
if (objSPI)
debug.Str(string("Started Successfully!",13))
else
debug.Str(string("Failed to Start!",13))
'display data from H48C & HM55B
if (objSPI)
data := %10101010
data := GetRev
debug.str(string("GetRev should equal 03h = "))
debug.bin(data,8)
debug.str(string(13))
debug.str(string("Done."))
else
debug.str(string("Error: SPI failed to start. Terminating...",13))
PRI GetRev : datar | i
'set MOSI, CSB, SCK out
dira [ SPI_MOSI ] := Out
dira [ SPI_CSB ] := Out
dira [ SPI_SCK ] := Out
dira [ SPI_MISO ] := %0
'set CLK, MOSI low
outa [ SPI_SCK ] := Low
outa [ SPI_MOSI ] := Low
'set CSB high, then low to reset it
outa [ SPI_CSB ] := High
outa [ SPI_CSB ] := Low
repeat 8
outa [ SPI_SCK ] := High 'set CLK High
outa [ SPI_MOSI ] := %0 'transmit bin '0' on MOSI
outa [ SPI_SCK ] := Low 'set CLK low
repeat i from 7 to 0
outa [ SPI_SCK ] := High 'set CLK High
'read MISO
if ina[SPI_MISO] == 1 'read MISO
datar |= |< i ' set bit i HIGH
else
datar &= !|< i ' set bit i LOW
outa [ SPI_SCK ] := Low 'set CLK low
outa [ SPI_CSB ] := High
return datar