Shop OBEX P1 Docs P2 Docs Learn Events
SPI a MLX90609 Gyro to a Stamp — Parallax Forums

SPI a MLX90609 Gyro to a Stamp

GusieGusie Posts: 2
edited 2009-03-23 23:16 in BASIC Stamp
Hi,

I am having difficult communicating a MLX90609 Gyro, on a Sparkfun Breakout board,·with a BS2. Would anyone have some sample code that works with this over the SPI. I was using the SHIFTIN and SHIFTOUT commands but I am going wrong somewhere. Not sure if I am sending the correct number of Bits. My code is below. Cut and paste into the Software Editor to straighten up..

Any help would be great.

All the best
Gus





' {$STAMP BS2}
' {$PBASIC 2.5}
'· attempt at using code to run the Melexis MLX90609 Gyro on The Spark Fun breakout board
' ============================================================================
'
[noparse][[/noparse] Pins/Constants/Variables ]
Din··········· PIN····· 6··················· ' Conected to MISO of Gyro Serial Output
Dout·········· PIN····· 7··················· ' COnected to MOSI of Gyro Serial Input
Clk··········· PIN····· 5··················· ' Pin5 of stamp sends pulses to Gyro Clk· (Pin3) of the sparkfun breakout board
En············ PIN····· 4··················· ' Pin4 controls HM55B's /EN(ABLE)
Reset········· CON····· %1001010000000000······· '1001010000000000· Step 1 -· max 16 bits for shiftout so send resetmore aswell
Resetmore····· CON····· %00000000··············· ' More bits for reset command for Gyr0 - this bits are dontcares X on datasheet anyway
Conversation·· CON····· %1001010000000000······· ' Start conversation measurement command··· step 2
Conmore······· CON····· %00000000··············· ' Start conversation measurement MOre dont care bits to make up 24 bit string······· CON····· %1100000000000000······· ' Get status/axis values command
ADCR·········· CON····· %1000000000000000······· ' Step 4 instruction to set ADC asleep
ADCRMore······ CON····· %00000000
slep·········· CON····· %1001000000000000······· ' sleep ADC
slepMore······ CON····· %0000000
'NegMask······· CON····· %1111100000000000······· ' For 11-bit negative to 16-bits
x············· VAR····· Word················ ' Gyro x-axis data were looking for
status1······· VAR····· Word················ ' Status flags
status2······· VAR····· Word················ ' Status flags
status3······· VAR····· Word················ ' Status flags ADC into Sleep mode
'
[noparse][[/noparse] Main Routine ]
DO·········································· ' Main loop
· GOSUB Start···················· ' Get Value from MSIO of Gyro

· DEBUG CR,CR,CR,CR,CR, "······ SBIN· - X······ = ",SBIN x, CR,
······················· "······ SDEC· - X······ = ",SDEC x, CR,··············· ' Displaying the values of x
······················· "······ DEC·· - X······ = ",DEC x, CR, CR············ ' as different types for no reason
· 'PAUSE 150································· ' Debug delay for slower PCs
LOOP········································· ' Repeat main loop

'
[noparse][[/noparse]STEP 1[noparse][[/noparse]
Start:
· HIGH En:·········· ' Disable SS
· PAUSE 30
· LOW En············ ' Set SS low to enable Gyro
· PAUSE 100
· SHIFTOUT Dout,clk,MSBFIRST,[noparse][[/noparse]Reset\16,Resetmore\8]····· ' STEP 1 - Put Gyro ADC in in active mode
· PAUSE 40·············································· ' should be able to do this in 8 bit mode. would be easier. Not sure how
· SHIFTIN· Din,clk,MSBPOST,[noparse][[/noparse]Status1\16]················· ' Read 16 bit Data from Gyro MISO
· DEBUG HOME,"Step 1 - Binary Sequence sent to Activate ADC······ =",BIN reset,CLREOL, CR
· DEBUG····· "······ - Answer···································· =" ,BIN Status1· ,CR ,CR
· '
[noparse][[/noparse] STEP 2 ]
· HIGH En:·········· ' Disable SS
· PAUSE 30
· LOW En············ ' Enable SS
· PAUSE 100
· SHIFTOUT Dout,clk,MSBFIRST,[noparse][[/noparse]Conversation\8]· '16,ConMore\8]· ' STEP 2 - conversation start measurement
········································································· 'command not sure mow many bits to send
· PAUSE 150
· SHIFTIN· Din,clk,MSBPOST,[noparse][[/noparse]Status2\16]····· 'Get Status after conversation - If 15th bit is zero, the instruction is accepted.
· DEBUG· "Step 2 - Binary Sequence sent to Conversation Start =",BIN conversation ,CLREOL, CR·· ' first 16 bits of series
· DEBUG· "······ - Answer···································· =",BIN Status2 ,CR ,CR
· '
[noparse][[/noparse] STEP 3 ]
· HIGH En:········· ' Disable SS
· PAUSE 30
· LOW En··········· ' Enable SS
· PAUSE 100
· SHIFTOUT Dout,clk,MSBFIRST,[noparse][[/noparse]ADCR\16,ADCR\8]·· ' Step 3 - send ADCR instruction and check 13th and 15 bits of ans.
· SHIFTIN· Din,clk,MSBPOST,[noparse][[/noparse]x\16]·· ' Get Gyro x Axis values
· DEBUG· "Step 3 - Send ADCR instruction and check··········· =",BIN ADCR,CLREOL, CR
· DEBUG· "······ - Conversation Over -· Value for x·········· =",BIN x ,CR ,CR
· '
[noparse][[/noparse] STEP 4 ]
· HIGH En:
· PAUSE 30
· LOW En
· PAUSE 100
· SHIFTOUT Dout,clk,MSBFIRST,[noparse][[/noparse]slep\16,slepMore\8]········· ' Put ADC back into sleep mode if required
· SHIFTIN· Din,clk,MSBPOST,[noparse][[/noparse]status3\16]·· ' Get x values
· DEBUG· "Step 4 - Put ADC into Sleep Mode··················· =",BIN slep, CR
· DEBUG· "······ - Gone to Sleep if Bit 15 High·············· =",BIN status3 ,CR··· ' Check 15th bit - 0 = done
·' IF (x.BIT15 = 0) THEN x = x | NegMask····· ' Store 16-bits as signed word

· RETURN

Post Edited (Gusie) : 7/14/2008 9:17:36 PM GMT

Comments

  • atstew01atstew01 Posts: 6
    edited 2009-03-23 23:16
    Did you ever get this to work? I am currently applying one of these to a project and could use any guidance available.

    Thanks
Sign In or Register to comment.