Defining address for 2 component compass

Hi all

I have followed a tutorial to create a tilt compensated compass using the HMC5883L compass and the ADXL345 accelerometer.
Both are stored as variables.

Is it possible to define them as a complete unit?
ie if I was using the following in my code

#define compassAddress 0x32 >> 1

How do i go about assigning both components a single address to reference from that address.

Excuse the terminology, it may be incorrect. I did a lot of googling trying to find an answer but realised I dont even know how to ask the question :slight_smile:
Hopefully it will make sense to someone

Thanks
Steve

You would need an intermediate device with 1 address that would then pass the message to one device or the other.

Bummer.
I never considered that.

Could I not just se it up so when I address the compass it runs a separate loop that encompasses both devices and returns the appropriate data?

Like nesting perhaps.

If not what sort of device might we be referring to?

Could be an AVR with I2C interface. Maybe one of the ATTiny devices.

Post links for 2 the devices you want to use.

This is the link to the HMC5883L
http://www.google.co.nz/url?sa=t&rct=j&q=hmc5883l&source=web&cd=1&cad=rja&ved=0CDcQFjAA&url=http%3A%2F%2Fwww51.honeywell.com%2Faero%2Fcommon%2Fdocuments%2Fmyaerospacecatalog-documents%2FDefense_Brochures-documents%2FHMC5883L_3-Axis_Digital_Compass_IC.pdf&ei=bfU7Ub2sBIOikQXu44GICw&usg=AFQjCNERVlsMXwth4SXIth4jIgNI8Y3gJg&sig2=d6hdUhYFIJLDARfhL76dig&bvm=bv.43287494,d.dGI
And the ADXL345
http://www.google.co.nz/url?sa=t&rct=j&q=adxl345&source=web&cd=2&cad=rja&sqi=2&ved=0CDYQFjAB&url=http%3A%2F%2Fwww.analog.com%2Fstatic%2Fimported-files%2Fdata_sheets%2FADXL345.pdf&ei=7PU7UZanAYfykAXg4IG4Aw&usg=AFQjCNFy6muK3LQUSYM8psaVQwl5M1hmvg&sig2=18jUFUDZF19X6cnBpthhLg&bvm=bv.43287494,d.dGI

I2C Address
8-bit read address 0x3D
8-bit write address 0x3C

With the ALT ADDRESS pin high, the 7-bit I2C address for the device is 0x1D, followed by the R/W bit.
This translates to 0x3A for a write and 0x3B for a read.
An alternate I2C address of 0x53 (followed by the R/W bit) can be chosen by grounding the ALT ADDRESS pin (Pin 12).
This translates to 0xA6 for a write and 0xA7 for a read.

So you've two different addresses, with wholly different data coming from each part.
3A/3B you get one's part info, 3C/3D you get the other.
Talk to both using normal library kind of calls.

No1Daemon:
I have followed a tutorial to create a tilt compensated compass using the HMC5883L compass and the ADXL345 accelerometer.
Both are stored as variables.

Is it possible to define them as a complete unit?

How do i go about assigning both components a single address to reference from that address.

I'm trying to guess why you're trying to do this, and I couldn't think of a reason. If you want to represent both devices as a single conceptual thing in your code, you could define a class to encapsulate them both. Or if classes aren't your thing you could just define a struct to contain the two addresses, and another struct to contain both sets of results, and a function to read the results from the devices.

Peter

At the end of the day all it does is the HMC outputs a bearing and then the ADXL corrects it for tilt and outputs a tilt compensated bearing.
All I require is to get the tilt compensated bearing with one call basicaly.
Suspected it would be hard to see wy I needed this, especially if you are experiences with code as I am not.

Regards
Steve

Have you seen this chip?
Tilt Compensated Compass Breakout - LSM303DLMTR - SEN-10888 - SparkFun Electronics?

"LSM303DLMTR Breakout Board - Tilt Compensated Compass"

Sounds kinda like what you're after: "a tilt compensated compass using the HMC5883L compass and the ADXL345 accelerometer"

Yes I did but but only after I have made one now out of seperate components so I will battle on.
Thanks for the replies guys.