Forum Index
I2C Help

 
Author Message
sturgessb



Joined: 25 Apr 2008
Location: Norwich, UK

Posted: 29 April 2008, 16:23 PM    Post subject: I2C Help

Hi Guys

Im trying to get the data from a LIS3LV02DQ SPI/I2C accelerometer
http://www.sparkfun.com/commerce/product_info.php?products_id=758

Im using a ZX-128ne, with the default channel 0 I2C lines, 11 and 12. I have these lines pulled up to 3.3v (its a 3.3v sensor) with 1k8 resistors.

The sensor, has an address of 3A and the register that I am trying to read the value of is 0F, this should return the address of the sensor so im just using it as a test.

The code im using is
Code:
DIM i2cRC as BYTE
DIM outputvalue as BYTE

i2cRC = I2CCmd(0, &H3A, 1, &H0F, 1, outputvalue)
DEBUG.PRINT i2cRC & " output=" & outputvalue

And the output im getting is.
Code:
1 output=0


So Im assuming from the 1, that it is sending the data ok, but why am I not getting '0' as a reply rather than '3A'.

Any ideas?

Also are there any performance issues related to using i2cCMD rather than individual i2cPutByte, i2cGetByte etc, any speed difference?

Regards
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Location: Portland, OR

Posted: 29 April 2008, 16:48 PM    Post subject: Re: I2C Help

sturgessb wrote:
Any ideas?
I believe that you should use code like this:
Code:
Const i2cChan as Byte = 0
Const slaveAddr as Byte = &H3a
Dim i2cRC as Integer
Dim sendData as Byte
Dim outputvalue as BYTE

sendData = &H0f
i2cRC = I2CCmd(i2cChan, slaveAddr, 1, sendData, 1, outputvalue)

The fourth and sixth parameters need to be a reference to one or more data values; you can't specify a value directly as you did in your original code for the fourth parameter. The compiler should have issued a warning; we'll need to look into why it did not.

As an aside, I edited your post to use code tags. You can either type these directly or select a sequence of text and then click the Code button just under the Subject edit box. Using the code tags for program code and output makes it more readable.

sturgessb wrote:
Also are there any performance issues related to using i2cCMD rather than individual i2cPutByte, i2cGetByte etc, any speed difference?
Using I2CCmd() is generally faster, not to mention easier, than constructing the same sequence using the low level functions. The difference in performance will be larger with VM devices than with native mode devices. The low level functions are provided for special cases where you can't get the interaction that you need with I2CCmd().
Back to top
sturgessb



Joined: 25 Apr 2008
Location: Norwich, UK

Posted: 29 April 2008, 17:13 PM    Post subject:

Many thanks, that was the answer!

still no sign of those packages Sad one day hopefully!

Cheers

Ben
Back to top
sturgessb



Joined: 25 Apr 2008
Location: Norwich, UK

Posted: 29 April 2008, 18:28 PM    Post subject:

Although im getting correct byte back from reg 0F, I cant seem to get anything other that '0' out of the actual axis reading.

Has anyone used this sensor before?

http://www.sparkfun.com/datasheets/IC/LIS3LV02DQ.pdf


Cheers

Ben
Back to top
mikep



Joined: 24 Sep 2005
Location: Austin, TX

Posted: 29 April 2008, 19:00 PM    Post subject:

sturgessb wrote:
Although im getting correct byte back from reg 0F, I cant seem to get anything other that '0' out of the actual axis reading.

Has anyone used this sensor before?
No I haven't. My experience with other I2C devices is that they work fairly well - see some of my application notes e.g. AN211 - Navigating the CMPS03 Magnetic Compass

This device also has an SPI interface. Perhaps you should try that and compare results.
Back to top
sturgessb



Joined: 25 Apr 2008
Location: Norwich, UK

Posted: 29 April 2008, 19:16 PM    Post subject:

I've got it working now with the following code


Code:

sendData = &H28
i2cRC = I2CCmd(i2cChan, slaveAddr, 1, sendData, 1, outputvalue2)
sendData = &H29
i2cRC = I2CCmd(i2cChan, slaveAddr, 1, sendData, 1, outputvalue1)
outputfinal = 256*Cint(outputvalue1)+Cint(outputvalue2)
Back to top
mikep



Joined: 24 Sep 2005
Location: Austin, TX

Posted: 29 April 2008, 19:45 PM    Post subject:

sturgessb wrote:
I've got it working now with the following code
Good. Check out the MakeWord routine:
Code:
outputFinal = MakeWord(outputvalue2, outputvalue1)
Back to top
sturgessb



Joined: 25 Apr 2008
Location: Norwich, UK

Posted: 29 April 2008, 21:10 PM    Post subject:

nice, even better.

Thanks Mike. Loving this zx-128ne. Although would be nice to have another timer, when are the 1281's going to be available.

Cheers

Ben
Back to top
mikep



Joined: 24 Sep 2005
Location: Austin, TX

Posted: 29 April 2008, 22:32 PM    Post subject:

sturgessb wrote:
Thanks Mike. Loving this zx-128ne.
That is good to hear.
sturgessb wrote:
Although would be nice to have another timer, when are the 1281's going to be available.
This question is possibly best answered in a different thread. The number of timers available and their usage is highly dependent on your application. Note that even though the mega1281 adds more timers, there are no additional I/O pins for things like PWM unless you use the 100pin mega1280. Also note that you may have more timers available than you think. For example it is highly unlikely that you are using logical serial ports on the ZX128ne as two USARTs are available and therefore the 8-bit timer2 is also available for the application.

As mentioned on my website, availability of the ZX-1281e and ZX-1281ne is planned for June 2.
Back to top
Display posts from previous:   
Page 1 of 1

 



ZBasic Microcontrollers Home
All content Copyright © 2005, 2006, 2007, 2008, 2009, 2010 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group