Boron Wire.endTransmission() hangs

I’m trying to use the I2C Wire interface with the Boron but am stuck just trying to get it working. The thought was, prove that there are no I2C devices in use, then wire one up and show that it exists. The firmware I cobbled together from many helpful posts in the forum is:

int     nDevices;
byte    error;
byte    address;


void setup() {
    
    Serial.begin(9600);
    delay(5000);
    
    // Initialize the I2C bus if not already enabled
    if (!Wire.isEnabled()) {
        Serial.println("Wire begin");
        Wire.begin();
    }
    delay(5000);
    
    
    if (Wire.isEnabled()) {
        Serial.println("Wire reset");
        Wire.reset();
    }
}


void loop() {
    
    Serial.println("Scanning...");
	nDevices = 0;
	for(address = 1; address < 127; address++ )
	{
	    Serial.println("Begin Transmission");
		Wire.beginTransmission(address);
		Serial.println("End Transmission");
		error = Wire.endTransmission(true);
		Serial.print("Error = 0x");
		Serial.println(error,HEX);
		
		if (error == 0)
		{
			Serial.print("I2C device found at address 0x");
			if (address<16)
				Serial.print("0");
			Serial.println(address,HEX);
			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");
	else
		Serial.println("done");
    
    Serial.println("Loop");
    delay(10000);

}

The resulting serial output is:

particle serial monitor --follow
Polling for available serial device…
Opening serial monitor for com port: "COM21"
Serial monitor opened successfully:
Wire begin
Wire reset
Scanning…
Begin Transmission
End Transmission
(hangs)

Nothing is hooked up at this point other than the USB and the antenna. I’ve tried adding a device, there’s no difference in the outcome. Called endTransmission with TRUE and FALSE, this does not change the outcome. What am I missing?

Your I2C bus needs pull-up resistors on SDA & SCL - even when there are no sensors/clients present.
Do you have these in place?

2 Likes

The device I first tried this with (before adding the device scan and stripping the firmware down) has built-in pull-up 4.7k ohm resistors, and endTransmission() was hanging. https://www.sparkfun.com/products/13314
BORON - TMP102
GND - GND
3V3 - Vin
D0/SDA - SDA
D1/SCL - SCL

Just now added the following for D2 to my setup() and added a 4.7k pull-up to D0 and to D1 each:
pinMode(D2, OUTPUT);
digitalWrite(D2, HIGH);

We’re still hanging on endTransmission. :frowning:

I’ve been having code freeze up from the endTransmission method on a boron with an I2C current sensor, but other I2C devices/sensors seem to work fine.

Has anyone figured out what exactly causes this?