SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By beretta
#178078
Hi
I am trying to change a code from HMC6343 to hmc5883. I need the compass address for the following code
Code: Select all
//Instruct compass to read echoes
  Wire.beginTransmission(compassAddress);  // transmit to device
  // the address specified in the datasheet is 66 (0x42)
  // but i2c adressing uses the high 7 bits so it's 33
  Wire.write(0x50);                       // Send a "Post Heading Data" (0x50) command to the HMC6343 
  Wire.endTransmission();                 // stop transmitting

  //Wait for readings
  delay(2);                               // datasheet suggests at least 1 ms

  //Request heading reading from compass
  Wire.requestFrom(compassAddress, 2);    // request 2 bytes from slave device #33
By waltr
#178094
the address specified in the datasheet is 66 (0x42)
The I2C in data sheets can be confusing.
0x42 = 0100 0010b but if this is the 7 bit address then it is 100 0010b and then shifted left to the 8 bit address + R/W register it is 1000 0100x = 0x84.
Then don't forget the lsb is the r/w bit so clear/set as needed.

Some data sheets get this address already shifted to the high order 7 bits.
I that case its 0x42 and the lsb is the R/W bit.

First try the 0x84 and if doesn't work then try non-shifted.
By beretta
#178114
waltr wrote:
the address specified in the datasheet is 66 (0x42)
The I2C in data sheets can be confusing.
0x42 = 0100 0010b but if this is the 7 bit address then it is 100 0010b and then shifted left to the 8 bit address + R/W register it is 1000 0100x = 0x84.
Then don't forget the lsb is the r/w bit so clear/set as needed.

Some data sheets get this address already shifted to the high order 7 bits.
I that case its 0x42 and the lsb is the R/W bit.

First try the 0x84 and if doesn't work then try non-shifted.
Please note this code is for HMC6343 so is the data sheet referred to.

r
By beretta
#178115
I have changed the address codes but I guess this needs changing too
Code: Select all
 
Wire.write(0x50);                       // Send a "Post Heading Data" (0x50) command to the HMC6343
 
Any ideas please.
By waltr
#178119
Since you determined the I2C base address is 0x1E then you change this to do a write command to the base address.

Ok on that being the other chip. I saw this address in the comments of the code You posted.
The info still applies but for a different address as in the data sheet.