sandeepmistry / arduino-nRF5

Arduino Core for Nordic Semiconductor nRF5 based boards
Other
892 stars 276 forks source link

i2c_scanner hangs on nRF52832 #443

Closed pvonmoradi closed 3 years ago

pvonmoradi commented 3 years ago

I'm using a simple I2C scanner to get the address of BNO055 (0x28 or 0x29). The following code hangs.

#include <Arduino.h>
#include <Wire.h>
#include "variant.h"

void setup() {

    Wire.setPins(10, 11);
    Wire.begin();

    pinMode(25, OUTPUT);
    digitalWrite(25, 1);
    digitalWrite(25, 0);
    Serial.setPins(PIN_SERIAL_RX, PIN_SERIAL_TX);
    Serial.begin(115200);
    Serial.println("\nI2C Scanner");
}

void loop() {
    byte error, address;
    int nDevices;

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

    nDevices = 0;
    for (address = 1; address < 127; address++) {
        // The i2c_scanner uses the return value of
        // the Write.endTransmission to see if
        // a device did acknowledge to the address.
        Wire.beginTransmission(address);
        Serial.print(address);
        error = Wire.endTransmission();

        if (error == 0) {
            Serial.print("I2C device found at address 0x");
            if (address < 16) Serial.print("0");
            Serial.print(address, HEX);
            Serial.println("  !");

            nDevices++;
        } else if (error == 4) {
            Serial.print("Unknow error at address 0x");
            if (address < 16) Serial.print("0");
            Serial.println(address, HEX);
        }
    }
    if (nDevices == 0)
        Serial.println("No I2C devices found\n");
    else
        Serial.println("done\n");

    delay(1000);  // wait 1 second for next scan
}

There are 4k7 pull-up resistances on SDA/SCL lines. Both are always high. Also checked with a logic analyzer. No activity on I2C lines. D0 is SCK, D1 is SDA, D2 is pin25 which we can see is toggled. image

The i2c_scanner detects the address of this sensor on an Arduino nano.

pvonmoradi commented 3 years ago

P0.09 and P0.10 are NFC pins by default (non-GPIO). CFLAGS += -DCONFIG_NFCT_PINS_AS_GPIOS fixed it.