I ve made my own shield for arduino. Part of that shield is a few sensors connected through pca9306 logic level translator. sensors are BMP085 ADXL345 HMC5843 and ITG3200, powered from arduinos 3.3v.
i use 510 ohms pull-ups on both sides of pca9306(took the average value of the datasheet).
The problem is: all sensors working fine except hmc5843(with 3 ceramic caps 4.7uf, 0.22 uf and 0.1uf). i ve tried next code
// Demonstration sketch for HMC5843 3-axis magnetometer (SparkFun SEN-09371)
// Mike Grusin, SparkFun Electronics, 8/20/2010
// i2c bus connections:
// connect SDA to analog 4
// connect SCL to analog 5
// power sensor with 3.3V from Arduino
// connect 5K-10K pullup resistors to SCA and SDL to 3.3V
#include <Wire.h>
void setup()
{
Wire.begin(); // set up i2c bus
Serial.begin(9600); // set up serial port
delay(10); // wait for HMC to boot up
setup_HMC5843(); // initialize HMC
}
void loop()
{
read_HMC5843(); // get all magnetometer results, loop
delay(1000);
}
void setup_HMC5843()
{
byte result;
Serial.print("setting up HMC\n");
Wire.beginTransmission(0x1E); // i2c address (use 7-bit address, wire library will modify for read/write)
Wire.send(0x02); // register to write (0x02 = mode register, see datasheet)
Wire.send(0x00); // write value to register (0.5Hz output rate, normal measurement configuration. See datasheet)
result = Wire.endTransmission();
printstatus(result);
}
void read_HMC5843()
{
int x,y,z;
byte xmsb,xlsb,ymsb,ylsb,zmsb,zlsb;
byte result;
Serial.print("ask for readings\n");
Wire.beginTransmission(0x1E); // i2c address (use 7-bit address, wire library will modify for read/write)
Wire.send(0x03); // register to read (0x03 = first result register, see datasheet)
result = Wire.endTransmission();
printstatus(result);
Wire.requestFrom(0x1E, 6); // read next six registers (0x03 to 0x08, see datasheet)
x = Wire.available(); // make sure read was successful
Serial.print(x, DEC); Serial.print(" bytes available\n");
if (x == 6)
{
xmsb = Wire.receive(); // read out six bytes = three readings (x,y,z)
xlsb = Wire.receive(); // each reading is split into two bytes (msb, lsb)
ymsb = Wire.receive(); // msb = most-significant byte ("high byte")
ylsb = Wire.receive(); // lsb = least-significant byte ("low byte")
zmsb = Wire.receive();
zlsb = Wire.receive();
x = word(xmsb,xlsb); // combine bytes to get readings
y = word(ymsb,ylsb); // result = msb*256 + lsb
z = word(zmsb,zlsb);
Serial.print("X "); Serial.println(x, DEC);
Serial.print("Y "); Serial.println(y, DEC);
Serial.print("Z "); Serial.println(z, DEC);
}
}
void printstatus(byte result) // Wire.endTransmission can tell you if an i2c transaction was successful or not
{
Serial.print("I2C status: ");
Serial.print(result, DEC);
switch (result)
{
case 0:
Serial.print(", success!\n");
break;
case 1:
Serial.print(", data too long to fit in transmit buffer\n");
break;
case 2:
Serial.print(", received NACK on transmit of address\n");
break;
case 3:
Serial.print(", received NACK on transmit of data\n");
break;
case 4:
Serial.print(", other error\n");
break;
}
}
the output i have is
setting up HMC
I2C status: 2, received NACK on transmit of address
ask for readings
I2C status: 2, received NACK on transmit of address
0 bytes available
ask for readings
I2C status: 2, received NACK on transmit of address
0 bytes available
ask for readings
I2C status: 2, received NACK on transmit of address
0 bytes available
ask for readings
I2C status: 2, received NACK on transmit of address
0 bytes available
i thought i could overheat or damage the sensor, so i ordered same from sparkfun and soldered it on 220 degrees, but problem are still here.
i have only 1 idea- problem is in the wrong pullups values, but atmel datasheet and pca9306 gives me absolutely different values, so i dont know which datasheet i must beleive.
also i disabled internall pullups in wire library.
Could someone help me please?