Shop OBEX P1 Docs P2 Docs Learn Events
Read data from MMA8451Q 3 axis acceleromter from Freescale Semiconductor — Parallax Forums

Read data from MMA8451Q 3 axis acceleromter from Freescale Semiconductor

cheolcheol Posts: 6
edited 2011-11-23 10:35 in BASIC Stamp
Hi,
I am trying to make I2C communication and read data from MMA8451Q, low cost 3 axis accelerometer. Below is the link and attached datasheet.

http://cache.freescale.com/files/sensors/doc/data_sheet/MMA8451Q.pdf?fpsp=1&WT_TYPE=Data Sheets&WT_VENDOR=FREESCALE&WT_FILE_FORMAT=pdf&WT_ASSET=Documentation


I am using Mobo stamp, and generate below code, but somehow I even cannot make I2C communication....as I couldn't read add nor control register values....Can anyone comment or help ...what is wrong and if I miss anything? I could make some other devices before using same approach...but this time doesn't work for MMA8451.MMA8451Q_rev1.0.bpe



' What's a microcontroller test photoresistor.bs2
' {$STAMP BS2pe}
' {$PBASIC 2.5}
'---- Pin/Constants/Variables ----
Clk PIN 9 'Coprocesser A for 8451, Clock pin in MoboStamp
Dat PIN 8 'Coprocesser A for 8451, Data pin in MoboStamp

accx VAR Byte 'for Xout, 8bit
accy VAR Byte 'for Yout, 8bit
accz VAR Byte 'for Zout, 8bit
add VAR Byte 'to read who am I register for 8451 in $0D
CNT VAR Byte 'to read control register
DO
I2COUT Dat, $3A, $2A, [%00011111]
I2CIN Dat, $3B, $01, [accx]
PAUSE 20
I2CIN Dat, $3B, $03, [accy]
PAUSE 20
I2CIN Dat, $3B, $06, [accz]
PAUSE 20

I2CIN Dat, $3B, $1A, [add]
PAUSE 20
I2CIN Dat, $3B, $2A, [CNT]
PAUSE 20

DEBUG HOME,"For MMA8451 ",CLREOL,
CR, "accx= ", DEC4 accx, CLREOL,
CR, "accy= ", DEC4 accy, CLREOL,
CR, "accz= ", DEC4 accz, CLREOL,
CR, "cnt reg value= ", BIN CNT, CLREOL,
CR, "8451 add= ", BIN add, CR
LOOP
Sign In or Register to comment.