error #4 for endTransmission with ak09970n (I2C)

This is my set up code:

  // initialize arduino baud rate
  Serial.begin(9600);

  // set up ODINT pin
  pinMode(ODINT_PIN, OUTPUT);
  digitalWrite(ODINT_PIN, HIGH);

  // I2C power on
  pinMode(RST_PIN, OUTPUT);
  digitalWrite(RST_PIN, LOW);

  // Initiate Wire library
  Wire.begin();

  byte bus_Status = 20;

  Serial.println("Start");
  
  do
  {
     Wire.beginTransmission(AKAddress);
     bus_Status = Wire.endTransmission();
     Serial.println(bus_Status);
     delay(500);
   }
   while(bus_Status != 0);

endTransmission() continues to return 4, however, I don't know what the error is (since 4 is other).

The AK9970 is a 3.3V chip and the Arduino Mega 2560 is a 5V board.

Error 4 is "4 .. other twi error (lost bus arbitration, bus error, ..)", that means the I2C bus is a big mess. If that error is consistant, then something is very wrong.

Stop trying so hard to destroy the sensor with 5V.

I am currently using a logic converter which converts 5V to 1.8V on a new sensor. I don't believe I have burnt this sensor out with such little voltage.

What kind of things should I check for to fix this kind of error?

Post links to the used hardware!

Are you powering the sensor with 1.8V or is that just the voltage of the I2C bus?

Do you use a bi-directional converter?

Post a wiring diagram!

And post complete code, the error is usually in that part of the code you didn't post.

Hardware:

Wiring Diagram:
(attached)

Code: (Never goes past the do while loop)

#include <Wire.h>

const byte RST_PIN = 5;
const byte ODINT_PIN = 10;

int AKAddress = 0b0001100;

const unsigned int CNTL2 = 0x21;
const unsigned int MODE_3 = 0b00101110;

const unsigned int WRITE = 0x1A;
const unsigned int READ = 0x1B;

const unsigned int SENSOR_STATUS = 0x17;


void setup() {
  // initialize arduino baud rate
  Serial.begin(9600);

  // Wire.setClock(100000);

  // set up ODINT pin
  // pinMode(ODINT_PIN, OUTPUT);
  // digitalWrite(ODINT_PIN, LOW);

  // I2C power on
  pinMode(RST_PIN, OUTPUT);
  digitalWrite(RST_PIN, LOW);

  delay(10000);
  Serial.println(digitalRead(RST_PIN));
  
  digitalWrite(RST_PIN, HIGH);
  delay(10000);

  // Initiate Wire library
  Wire.begin();
  delay(10000);
  Serial.println(digitalRead(RST_PIN));

   byte bus_Status = 20;

   Serial.println("Start");
   
   do
   {
      Wire.beginTransmission(AKAddress);
      bus_Status = Wire.endTransmission();
      Serial.println(bus_Status);
      delay(500);
    }
    while(bus_Status != 0);
  

  // set sensor to 100 Hz high sensitivity measurement mode
  Wire.beginTransmission(AKAddress);
  Wire.write(WRITE);
  Wire.write(CNTL2);
  Wire.write(MODE_3);
  bus_Status = Wire.endTransmission();
  
  Serial.println(bus_Status);

  delay(100);

  // Format Data Display
  Serial.println("AK009970N Data Information");
  Serial.println("\nAddress:  Description:                          Bits:");

  
}

I realize that my code could be commented better, so please let me know if that is something you would like me to do.

Thank you!

AK09970N-E-00.pdf (1.08 MB)

i2c_wiring_diagram.PNG

Wiring Diagram:
(attached)

If that's correct, you missed the level converter. And I would like to see where exactly you connected the different signal on the Arduino.

If you wired according to the schematics you posted the I2C address is 0x0d and not 0x0c as you used it. Did you try an I2C scanner sketch on your setup?

What do you mean by you missed the level converter?

I connected the SDA and SCL pins to 20 and 21 (the designated SDA and SCL pins).

Is the I2C scanner sketch an example in Arduino?

@aapatil, to be able to help you, we really have to know the circuit. You can write it on a piece of paper and make a photo of it.
Do you also use a level shifter for ODINT ?
Where is the 1.8V coming from ?
Is the 1.8V also connected to the "LV" of the level shifter ?
How long are the wires of SDA and SCL ?
Do you use a breadboard (with bad contacts) ?

What do you mean by you missed the level converter?

In the posted schematics (which is copied from the datasheet, p.40) there is no level converter, just the AK09970 and a MCU.

Do you also use a level shifter for ODINT ?

And for RSTN?

I can post my circuit tomorrow morning if it is still relevant; however, for the time being, I have switched to an Arduino Pro Mini 3.3V and have connected the sensor to the arduino exactly as the wiring diagram indicated. I now continue to get 2 from endTransmission. What kinds of things should I be checking to fix for this kind of error (besides incorrect wiring and incorrect address)?

If you have a working I2CLCD, check it with your Arduino and observed that you have got 0 (zero) on the Serial Monitor after the execution of the following codes. This will ensure that the I2C Bus at the Arduino side is OK?

dor
{
   Wire.beginTransmission(slaveAddress);  //0x27 or 0x3F
   busStatus = Wire.endTransmission();
}
while(busStatus != 0x00);
Serial.println("I2CLCD is Present....!");

I had the Mega2560 from before and connected it to the Pro Mini with the level converter in between and used this arduino tutorial: https://www.arduino.cc/en/Tutorial/MasterReader. I2C worked for this.

I now continue to get 2 from endTransmission. What kinds of things should I be checking to fix for this kind of error (besides incorrect wiring and incorrect address)?

Error two means a missing ACK after sending the I2C address of the slave. Besides the two reasons above I only see that you fried your sensor.