Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:21 26 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : DM I2C LSM303DLM

Author Message
jlder
Newbie

Joined: 30/09/2012
Location: France
Posts: 2
Posted: 02:57am 30 Sep 2012
Copy link to clipboard 
Print this post

I am trying to connect to an LSM303DLM which is on a 9DOF Drotek board using I2C with a DM eMega.
Up to known I have had zero luck.
I connected the external board to UEXT 1 for Vdd, 2 for GND, 5 for clock and 6 for data.

I used the following code to:
- initialize I2C
- set the chipo to 30 Hz
- set the gain for 1.3 Gauss
- set the continuous mode
- and read the 6 byte to get the 3 axis.

I test MM.I2C after each I2C instruction and get a nack every time.
What is strange is that I also get nack when ecternal board is not powered.

Any advise on what I am doing wrong?

Thanks,
JLD



Here is the code (line numbers are supposed to go every 10).

MAGXH=0
MAGXL=0
MAGYH=0
MAGYL=0
MAGZH=0
MAGZL=0
I2CEN 100,100 'enable I2C
I2CSEND &H1E, 1, 2, &H00, &H14 'ODR to 30 Hz
? "0=ok 1=nack 2=timeout"; MM.I2C
I2CSEND &H1E, 1, 2, &H01, &H20 'Gain for 1.3 Gauss
? "0=ok 1=nack 2=timeout"; MM.I2C
I2CSEND &H1E, 1, 2, &H02, &H00 'Continuous mode
? "0=ok 1=nack 2=timeout"; MM.I2C
I2CRCV &H1E, 1, 1, MAGXH, 1, &H03 'read X high
? "0=ok 1=nack 2=timeout"; MM.I2C
I2CRCV &H1E, 1, 1, MAGXL, 1, &H04 'read X low
? "0=ok 1=nack 2=timeout"; MM.I2C
I2CRCV &H1E, 1, 1, MAGYH, 1, &H05 'read Y high
? "0=ok 1=nack 2=timeout"; MM.I2C
I2CRCV &H1E, 1, 1, MAGYL, 1, &H06 'read Y low
? "0=ok 1=nack 2=timeout"; MM.I2C
I2CRCV &H1E, 1, 1, MAGZH, 1, &H07 'read Z high
? "0=ok 1=nack 2=timeout"; MM.I2C
I2CRCV &H1E, 1, 1, MAGZL, 1, &H08 'read Z low
? "0=ok 1=nack 2=timeout"; MM.I2C
PRINT "X ="; HEX$(MAGXH*256+MAGXL); TAB(10);
PRINT "Y ="; HEX$(MAGYH*256+MAGYL); TAB(20);
PRINT "Z ="; HEX$(MAGZH*256+MAGZL)
IF INKEY$ <> "" THEN 320 'end if key is pressed
PAUSE 300 'wait a little
GOTO 140 'read and print again
I2CDIS

 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 09:29am 30 Sep 2012
Copy link to clipboard 
Print this post

You should have a read of this http://www.pololu.com/catalog/product/1273 especially the part about addresses and Protocol Hints.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024