Shop OBEX P1 Docs P2 Docs Learn Events
ShiftIn Data — Parallax Forums

ShiftIn Data

ArchiverArchiver Posts: 46,084
edited 2003-12-23 03:29 in General Discussion
OK, this problem has been bugging me for a number of days now. I am trying to
use
a BS2p to interface with a new module from my company. The interface is pretty
straight forward. The frame sent and received consists of multiple bytes (or
words)
starting with a "flag" ($AA) and ending with a terminator($00). In the
beginning I had
no problem with ShiftIn and multiple bytes but I am now trying to shiftin
mulitple
bytes with 2 words interpaced within. The words are signed 16 bit values. The
first
byte/word (XRaw) combination is comming through correctly, but the second set of

byte/word (YRAW) is wrong. I know it is not the second values because if I
request
only the "second" value all is fine.

Any suggestions?

'{$Stamp BS2p} 'Stamp Directive (specifies BS2P)

'Declare Lines
SYNC CON 5 'SYNC is pin 5
SSNOT CON 7 'SSNOT is pin 7
MOSI CON 8 'MOSI is pin 8
MISO CON 9 'MISO is pin 9
SCLK CON 10 'SCLK is pin 10

'Declare Global Constants for Command Datagrams
Flag CON $AA 'Defines Sync Flag which is the first byte of any
command
GetModInfo CON $1 'Defines the frame type that queries the
V2Xe for module information
ModInfoResp CON $2 'Defines the response frame type to command
GetModInfo
SetDataComponents CON $3 'Defines the frame type for the data components
to be sent back
XRaw CON $1 'Defines the Component ID for X sensor
RAW Data
YRaw CON $2 'Defines the Component ID for Y sensor
RAW Data
Heading CON $5 'Defines the Component ID for Heading
Mag CON $6 'Defines the Component ID for Magnetude
Dist CON $8 'Defines the Component ID for the distortion flag
CalStatus CON $9 'Defines the Component ID for calibration status

SaveConfig CON $9 'Defines the SaveConfig frame type
GetData CON $4 'Defines the frame type which queries the V2Xe
for data components
DataResp CON $5 'Defines the response to command GetData frame
type
Term CON $00 'Defines Terminator which is the last byte of any
command



'Declare Variables for Response Datagrams
FlagIn VAR BYTE 'Defines Sync Flag in the response Datagram
FrameIn VAR BYTE 'Defines the Frame Type in the response
Datagram
CountIn VAR BYTE 'Defines the number of components in the
response Datagram
XRawIn VAR BYTE 'Defines the XRaw ID in the response Datagram
XRawVal VAR WORD 'Defines the signed 32 bit XRaw value in the
response Datagram
YRawIn VAR BYTE 'Defines the YRaw ID in the response Datagram
YRawVal VAR WORD 'Defines the signed 32 bit YRaw value in the
response Datagram
TermIn VAR BYTE 'Defines the Terminator of the resonse Datagram



'Set the data componets to be read from the V2Xe (XRaw and YRaw)
HIGH SSNOT
LOW SSNOT
LOW SYNC
HIGH SYNC
LOW SYNC
ShiftOut MOSI,SCLK,MSBFirst,[noparse][[/noparse]Flag,SetDataComponents,$2,XRaw,YRaw,Term]
Pause 1
ShiftOut MOSI,SCLK,MSBFirst,[noparse][[/noparse]Flag,GetData,Term]

Loop:
ShiftIn MISO,SCLK,MSBPre,[noparse][[/noparse]FlagIn]
If FlagIn <> $AA THEN Loop

ShiftIn
MISO,SCLK,MSBPre,[noparse][[/noparse]FrameIn,CountIn,XRawIn,XRawVal\16,YRawIn,YRawVal\16,TermIn]

Pause 1
High SSNOT

DEBUG HEX ? FlagIn
DEBUG HEX ? FrameIn
DEBUG HEX ? CountIn
DEBUG HEX ? XRawIn
DEBUG BIN ? XRawVal
DEBUG SDEC ? XRawVal
DEBUG HEX ? YRawIn
DEBUG BIN ? YRawVal
DEBUG SDEC ? YRawVal
DEBUG HEX ? Term

END
Sign In or Register to comment.