Wire.endTransmission() always returns 0


So I haven’t had a chance to work with the Bluz modules in quite a while and since then there appear to have been several firmware updates.

I went ahead and updated my Bluz module to the latest 2.1.50 system firmware and flashed in some code for detecting I2C devices on the bus. This firmware works well on Photon and is pretty basic. All it does is scan through all possible I2C addresses on the bus and then publishes a Particle Cloud Event with the addresses of all I2C connected devices.

The problem I am seeing is that Wire.endTransmission() is always returning 0(A.K.A success) on all addresses in the loop so it seems like there is a device at every possible address which is not accurate. So my event shows a device on all I2C addresses. Here is the code:

void setup() {
    //Set the speed of the I2C port on the Photon and start it.

void loop() {
    bool devicesFound = false;
    String newDevices;
    //Step through all 127 possible I2C addresses to scan for devices on the I2C bus.
    for(int i = 1; i < 128; i++){
        //Make a general call to device at the current address to see if anything responds.
        byte status = Wire.endTransmission();
        if(status == 0){
            //Device found so append it to our device list event string
            char devices[20];
            sprintf(devices, "Device at: %i\n", i);
            devicesFound = true;
        Particle.publish("New Devices", newDevices);
        Particle.publish("New Devices", "No Devices Found");

This is how I detect I2C devices on Arduino and Particle platforms. It has always served me well and appears to be a very common way of doing this. Any ideas? Is this a small bug in the .endTransmission function or should I approach this differently on Bluz for some reason?


So we use the Nordic driver directly for I2C, and I am wondering if their definition for Success is different then the Arduino definition. Nordic seems to inmply that Success just means he driver wasn’t busy or had a failure: http://infocenter.nordicsemi.com/index.jsp

I will look into the driver a little more to see if we can make things more inline with the Arduino definition.


Thanks @eric and good hearing from you again :slight_smile:
Let me know what you find out.