I2c Low Level functions cause hang

I am trying to use an i2c multiplexer from Adafruit

There is no library for this device, as all communication is handled through the Wire.h library.

I am going to leave a lot of irrelevant code out and keep the code up to the point of hang.

// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_FXOS8700.h"

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_FXOS8700.h>

#define TCAADDR 0x70

void tcaselect(uint8_t i) {
  if (i > 7) return;
  Serial.println("Beginning Transmission");
  Wire.beginTransmission(TCAADDR);
  Serial.println("Writing...");
  Wire.write(1 << i);
  Serial.println("Ending Transmission");
  Wire.endTransmission();  
  Serial.println("Ended...");
}


/* Assign a unique ID to this sensor at the same time */
Adafruit_FXOS8700 accelmag = Adafruit_FXOS8700(0x8700A, 0x8700B);

void setup(void)
{
  Serial.begin(9600);

  /* Wait for the Serial Monitor */
  while (!Serial) {
delay(1);
  }

  Serial.println("FXOS8700 Test"); Serial.println("");

  tcaselect(0);
  Serial.println("Checking Accelmag");
  /* Initialise the sensor */
  if(!accelmag.begin(ACCEL_RANGE_4G))
  {
/* There was a problem detecting the FXOS8700 ... check your connections */
Serial.println("Ooops, no FXOS8700 detected ... Check your wiring!");
while(1);
  }
}

The serial monitor prints the following:
FXOS8700 Test
Beginning Transmission
Writing…
Ending Transmission

You can see that it hangs after calling the Wire.endTransmission() function when it actually sends out the data.

If I am doing something wrong or using a deprecated function let me know.

Thanks,
Brandon

I don’t see a Wire.begin() in your setup code.

You need this just like you need Serial.begin(..) before using the serial port.

https://docs.particle.io/reference/firmware/photon/#begin--4

Obviously you are using a private Adafruit_FXOS8700 library as I’m not able to see it in the public Particle IDE repository.
If you want assistance with that we’d need to see the implementation of that library too.

But since we can’t check whether or not the library does call Wire.begin() internally @HEng’s advice sounds about right.

BTW, this potentially indefinet while(1); loop in your code are a bad idea if you want to stay connected to the cloud in case of an error.
You may rather want to use while(1) Particle.process();.

Oh you are right, Wire.begin() fixed the issue. It worked on the 32u4 processor without it, but that probably has something to do with the BSP for that particular unit.

As for the library it all works fine manually copy and pasting the content of the library to files within Particle.io. I contemplated creating a public library with it to help others out, but the CLI needs specific generated files not found on the repo. If someone else wants to add the library I can confirm it works on the Photon with no errors.

Also thanks for that tip about Particle.process, I was wondering how to avoid that dreadful SOS/ Breathing green

If you want to create the required files you should be able to do that via particle library create