-1

I have a really weird problem, when I run the exmple wire (I2C) scanner from Arduino, I get:

I2C Scanner Scanning... I2C device found at address 0x1E ! done

However when I try directly to the 0x1E I get the following error code 2:

received NACK on transmit of address.

Below is my code that i did only modify the example code:

#include <Wire.h>

void setup() {
  Wire.begin();

  Serial.begin(9600);
  while (!Serial); // Leonardo: wait for Serial Monitor
  Serial.println("\nI2C Scanner");
}

void loop() {

  Serial.println("Scanning...");

  byte address = 0x1E;

  Wire.beginTransmission(address);
  byte error = Wire.endTransmission();

  if (error == 0) {
    Serial.print("I2C device found at address 0x1E");
  } else if (error == 1) {
      Serial.print("data too long to fit in transmit buffer.");
  }
  else if (error == 2) {
      Serial.print("received NACK on transmit of address.");
  }
  else if (error == 3) {
      Serial.print("received NACK on transmit of data.");
  }
  else if (error == 4) {
      Serial.print("Unknown error at address 0x");
  }

  delay(5000); // Wait 5 seconds for next scan
}
4
  • please add a clear, answerable question to your post
    – jsotola
    Oct 28, 2022 at 22:56
  • It is very clear that I am asking what is wrong ? please do not comment just to comment.
    – Ana Houa
    Oct 29, 2022 at 8:56
  • not everyone would ask the same question ... this is a Q&A site, so a clear question is required
    – jsotola
    Oct 29, 2022 at 17:07
  • What is your pull-up resistor's value? NACK on Addressing could happened if you have weak pull-up, or if the device is busy.
    – hcheung
    Oct 31, 2022 at 7:24

1 Answer 1

0

There are certain situations where the device can send a nack after a valid address is sent - search "received NACK on transmit of address". Nothing I read applies specifically to your situation.

I see nothing in the HMC5983 datasheet (https://www.farnell.com/datasheets/1509871.pdf?_ga=2.219060057.1318745487.1555987311-293789508.1555987311) that could account for what you are seeing.

I don't have an HMC5983 on a GY282 module (you mentioned the module in a different forum) as you do, but I have it's predecessor, HMC5883 which I think is largely comparable, but slower.

I tested your code and I DID NOT get the NACK error - it simply reported finding the the device.

Then, I tested the leanest HMC5883 code I could find and I saw systematic output, which changed as I moved the device.

Then I tested similar code for the HMC5983 (see https://wiki.eprolabs.com/index.php?title=GY-282_HMC5983_Module#Hardware_Connections). That code worked on my slower HMC5883 board (e.g., systematic output).

I suggest the following - double check the solder blobs on the board to make sure I2C/SPI is jumpered properly - also the 3v3 CS blobs - a picture would be helpful.

I would also suggest that you try to run the HMC5983 code that I linked and see what you get.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.