Boron <-> Photon2 I2C & Type 14 Error

I am attempting to connect a Boron and P2 through an I2C connection. When I complete the SDA & SCL connections, the P2 immediately throws a type 14 heap error and resets.

My Boron is acting as a the central device to utilize cellular to communicate back to the cloud. It's Tx/Rx pins are in use with another device.

I've connected D0 on the Boron & P2 as well as D1 on the Boron & P2. Each have a pull up resistor.

My firmware is scanning for available addresses in order to confirm it can connect with the P2. But immediately upon completing the SDA/SCl circuit the error gets thrown.

Any ideas on how to avoid a type 14 error? Is there a different communication protocol I should use?

Here is my Boron code:

#include "Particle.h"

const int PHOTON_ADDRESS = 0x08; // I2C address of the Photon 2

void setup() {
    Wire.begin(); // Join the I2C bus as a central device
    Serial.begin(9600);
    while (!Serial.isConnected()) {
        delay(100);
    }
    Serial.println("I2C setup complete");
}

void loop() {
    Serial.println("Requesting data from Photon");

    // Request data from the Photon 2
    Wire.requestFrom(PHOTON_ADDRESS, 32); // Request 32 bytes from the Photon 2

    // Read the response
    String response = "";
    while (Wire.available()) {
        char c = Wire.read();
        response += c;
    }

    // Print the response to the serial monitor
    if (response.length() > 0) {
        Serial.println("Received from Photon: " + response);
    } else {
        Serial.println("No response from Photon");
    }

    delay(1000); // Wait for 1 second before the next request
}

and the P2 code:

// Photon 2 I2C Peripheral Code
#include "Particle.h"

void setup() {
    Serial.begin(9600);
    Wire.begin(0x08); // Join the I2C bus with address 0x08
    Wire.onRequest(requestEvent); // Register the request event handler
    Particle.publish("I2C setup complete!");
}

// Function to handle request from the central device
void requestEvent() {
    Particle.publish("I2C request received");

    // Send a response to the Boron
    Wire.write("Hello from Photon 2!");
    Particle.publish("Response Sent");
}

void loop() {
    // Main loop can perform other tasks
    delay(1000);
}

Hi @zachd can you try removing the Particle.publish calls from your requestEvent callback on your Photon? Try replacing the publish calls with serial logging and see if you are able to get any output.

1 Like

@zachd you will also need pull-up resistors (4.7K to 10K) on the I2C lines.

1 Like

Hi, @peekay123 - thanks for the help. I've got a 10k resistor connected to a positive terminal on each of the I2C lines. Is that too far towards the end of the acceptable range?

1 Like

@ericpietrowicz, thank you! I replaced the Particle.publish() with Serial.println() and I am both getting logs and not routinely creating the error.

I did reproduce the error once. But after reflashing the same code to the P2, everything is working as expected.

Seems pretty sensitive, but as I upgrade my code to actually transfer critical data we will see how reliable it is.

@zachd, I'm speculating a bit here as I don't know the driver intimately, but I would avoid doing any "work" at all in the callback function. Try to return as quickly as possible. Even the Serial.print might be too intensive (depending on how the driver was written).

I might recommend just setting a global flag in the callback function and returning. You can do your serious work such as the Particle.publish in the main loop after reading the flag that was set by the interrupt.

2 Likes