PDA

View Full Version : spi and shiftin/out



scorpion
- 8th December 2006, 09:01
Hi Im using a qt511 touch sensor from qprox.com and im having problems communicating with it.
basically i cant read and im assuming that i cant write to it either.
here are some code snipits.
---------------------------------------------------------------
include "modedefs.bas"
define shift_pauseus 40
Define OSC 20 '20Mhz HS xtal

sdo var porta.0
sdi var porta.1
sclk var porta.2
drdy var porta.3
ss var porta.4
det var porta.5

TRISA = %101010
TRISB = %00000001
TRISC = %00110000

ADCON1 = %00001111
ccp1con = 0
ccp2con = 0

high sclk
high led1
high led2
high led3

'allow touch sensor to calibrate

high ss

for i = 1 to 500
pause 1
USBService
next i
calibratesensor:

if drdy = 1 then goto MainLoop
pause 1
goto calibratesensor

MainLoop:
if sensorprepped = 0 then gosub sensorprep
if drdy = 1 then
if driftcntr > 100 then
gosub driftcomp
driftcntr = 0
else
gosub gettouch
endif
endif
led1 = ~ touched


GetTouch:

low ss
pauseus 15
shiftin sdi, sclk, 6, [touchin]
toucher = touchin & %10000000
if toucher = 0 then
touched = FALSE
else
touched = TRUE
endif
sensorprepped = 0
return

driftcomp:
low ss
pauseus 15
shiftout sdo,sclk, 5, [3]
sensorprepped = 0

return

sensorprep:
high ss
pauseus 15
low ss
pauseus 2
high ss
sensorprepped = 1
driftcntr = driftcntr + 1
return


PS. no oscilloscope just 3 onboard leds.......


sorry thats so long.
if anyone can spot what im doing wrong i would really appreciate it.
tia

scorpion
- 11th December 2006, 03:27
anyone have any help to offer?
Im really stuck here

scorpion
- 14th December 2006, 09:44
if i can provide any more info i would be glad to... can anyone help?