Help Make Sense of QT510 SPI Protocol


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    the only thing I've found is this site
    http://www.tigoe.net/pcomp/code/arch...o/000331.shtml

  2. #2
    Join Date
    Jan 2006
    Posts
    5


    Did you find this post helpful? Yes | No

    Default

    Well I've been tinkering a bit more. I did a new board layout on some thinner material. I'm using a 5V regulator instead of a 3.3V one so that my levels are the same between the pic and the sensor IC. Still, I cant seem to get DRDY to go high...but if I force it data transmits just fine. I've attached my code below, it could use a bit of improvement but it works with a PIC16F88

    '************************************************* ***************
    '* Name : QT510.BAS *
    '* Author : George Collier *
    '* Notice : Copyright (c) 2006 *
    '* : All Rights Reserved *
    '* Date : 01/13/2006 *
    '* Version : 1.0 *
    '* Notes : QTouch 510 Interface Test *
    '* : *
    '************************************************* ***************
    @ DEVICE WDT_OFF, MCLR_OFF
    @_INTRC_OSC_NOCLKOUT ' Set to internal osc
    DEFINE OSC 8
    DEFINE LCD_DREG PORTA
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTA
    DEFINE LCD_RSBIT 4
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 3
    DEFINE LCD_COMMANDUS 2000
    DEFINE SHIFT_PAUSEUS 1000

    'added for the 16F88
    'OSCCON = %01100000 ' set internal osc to 4 MHZ
    OSCCON = %01110000 ' set internal osc to 8 MHZ
    CMCON = 7 ' shut off comparators
    ADCON1 = 7 ' PORTA digital
    TRISA = %11000000 ' Set PORTA to all outputs, A6 and A7 Input
    TRISB = %00000000 ' Set PORTB to all outputs
    '@_INTRC_OSC_NOCLKOUT ' Set to internal osc
    'end add for 16F88
    ANSEL = 0 'set all ports digital

    I CON 254 ' Control Byte
    CLR CON 1 ' Clear the display
    LINE_1 CON 128 ' Point LCD to beginning of line 1
    LINE_2 CON 192 ' Point LCD to beginning of line 2
    LINE_3 CON 148 ' Point LCD to beginning of line 3
    LINE_4 CON 212 ' Point LCD to beginning of line 4
    CGRAM CON 64 ' Point to Cgram within LCD
    SHIFT_L CON 24 ' Shift LCD display left
    SHIFT_R CON 28 ' Shift LCD display right

    SDO var PORTB.1 : LOW SDO ' PIC Data out pin
    SDI VAR PORTA.6 : LOW SDI ' PIC Data in pin
    SCLK var PORTB.6 : high SCLK ' PIC Clock out pin
    qtSS var PORTB.7 : HIGH qtSS ' QTouch Slave Select Pin
    DRDY VAR PORTA.7 : LOW DRDY ' QTouch DRDY Pin (INPUT)
    'INPUT PORTA.7 'set DRDY pin to input

    QT_POSN VAR Byte : QT_POSN = %01000000 ' Stores QTouch Position Data
    QT_CFG_NULL VAR BYTE : QT_CFG_NULL = %00000000 'QTouch Null Command
    QT_CFG_PROX VAR BYTE : QT_CFG_PROX = %01001010 'Qtouch Proximity Sensitivity
    QT_CFG_TOUCH VAR BYTE : QT_CFG_TOUCH = %10001010 'Qtouch Touch Sensitivity
    QT_CFG_DRIFT VAR BYTE : QT_CFG_DRIFT = %00000011 'Qtouch Drift Compensate
    QT_CFG_CAL VAR BYTE : QT_CFG_CAL = %00000001 'Qtouch Calibration Command
    READS VAR BYTE : READS = 0 'Counter for periodic drift compensation
    STAT VAR QT_POSN.7 'QTouch STATUS

    Pause 2000 ' Wait for LCD to startup

    Lcdout $fe, 1 'Clear the LCD
    LCDOUT " QWheel Test "
    GOSUB INITIALIZE
    PAUSE 2000
    LCDOUT I, CLR
    LCDOUT I, LINE_2, "READY FOR DATA"
    GOTO LOOP

    INITIALIZE:
    IF DRDY = 1 THEN 'check if QTouch ready for data
    PAUSEUS 13
    Low QTSS 'Ready the QTouch to receive Data
    SHIFTOUT SDO, SCLK, 5, [QT_CFG_PROX] 'Configure Proximity Sensitivity
    HIGH qtss
    PAUSEUS 100
    LOW QTSS
    PAUSEUS 13
    SHIFTOUT SDO, SCLK, 5, [QT_CFG_TOUCH] 'Configure Touch Sensitivity
    HIGH qtSS
    PAUSEUS 100
    LOW QTSS
    PAUSEUS 13
    SHIFTOUT SDO, SCLK, 5, [QT_CFG_NULL] 'Send NULL Command
    HIGH qtSS 'Close the connection
    pause 500
    LCDOUT I, LINE_2, "INITIALIZE COMPLETE"
    ENDIF
    RETURN

    LOOP:
    if DRDY = 1 THEN GOSUB READ_QT
    GOSUB QT_LCD
    PAUSE 500
    GOTO Loop

    CALIBRATE:
    PAUSEUS 13
    LOW qtSS
    SHIFTOUT SDO, SCLK, 5, [QT_CFG_CAL\8] 'send the recalibrate command
    HIGH QTSS
    RETURN

    QT_LCD:
    SELECT CASE STAT 'determine touch status and output data

    CASE 1 'board is touched
    LCDOUT I, CLR
    LCDOUT "TOUCHED"
    QT_POSN = QT_POSN / 2 'strips the position bit from QT_POSN
    LCDOUT I, LINE_2, "POSITION: ", DEC QT_POSN 'prints position 0-127 on LCD
    PAUSE 100
    CASE 0 'board is not touched
    LCDOUT I, CLR
    LCDOUT I, LINE_1, "NOT TOUCHED"
    LCDOUT I, LINE_2, "NO POSITION"
    'if (QT_POSN.1 = 1) and (DRDY = 1) then GOSUB CALIBRATE 'recalibrate on error flag
    ' LCDOUT I, LINE_2, "RECALIBRATED"
    ' Pause 1000
    END SELECT
    RETURN

    READ_QT:
    LOW SDO 'Send all 0 on SHIFTIN = Null Command
    LOW qtSS 'Activate QTouch
    PAUSEUS 13
    SHIFTIN SDI, SCLK, 6,[QT_POSN\8] 'read position data to QT_POSN
    HIGH qtSS 'Deactivate QTouch
    STAT = QT_POSN.7 'get the touch status from the output 0 = not touched
    READS = READS + 1 'increment reads counter for drift compensation
    if (READS > 10) and (STAT = 0) then 'drift compensate every 10 reads if no touch
    LOW SDO
    LOW qtSS 'Activate QTouch
    PAUSEUS 13
    SHIFTOUT SDO, SCLK, 5, [QT_CFG_DRIFT] 'Drift Compensate
    HIGH qtSS
    PAUSEUS 20
    READS = 0 'reset the reads counter
    ENDIF
    RETURN

    END

Similar Threads

  1. Winbond ISD1700 Voice Recorder
    By RFEFX in forum mel PIC BASIC Pro
    Replies: 58
    Last Post: - 22nd April 2014, 10:00
  2. Replies: 17
    Last Post: - 12th April 2014, 02:17
  3. Using SPI with External Interrupts
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th June 2008, 04:08
  4. 16-bit SPI problem
    By shaiqbashir in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th June 2008, 15:42
  5. How to configure SPI in PICBASIC PRO?
    By moogle in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 15th April 2007, 18:31

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts