IIC hangs when D3 is interrupt

Hi,

I’m porting my project from a core to a photon.
I have run into an issue where IIC is not working when D3 is configured as an interrupt pin.

When D3 is configured as an interrupt pin Wire.endTransmission(true); will cause the photon to hang with the status LED stopping its cyan breathing and just remain solid cyan.

Have i missed something in the documantation about this? or does anybody have an idea about what could be wrong?

I made an as simple as possible project that will show the problem. This is shown below:

TCPServer server = TCPServer(23);
TCPClient client;
char response;
bool bStart = false;

void setup()
{
    server.begin();
    Wire.begin();
    pinMode(D3, INPUT);
    attachInterrupt(D3, RtcInterrupt, RISING);
}

    
void loop()
{
    if ( client.connected() ) 
    {
        while ( client.available() ) 
        {
            response = client.read();
            if( response == 'l' )
            {
                client.println(WiFi.localIP());
                client.println(WiFi.subnetMask());
                client.println(WiFi.gatewayIP());
                client.println(WiFi.SSID());
            }
            if( response == 'c' )
            {
                client.println("1");delay(100);
                Wire.beginTransmission((0x40>>1));
                client.println("2");delay(100);
                Wire.write(0x14);   
                client.println("3");delay(100);
                Wire.write(0x00);
                client.println("4");delay(100);
                client.println(Wire.endTransmission(true));
                client.println("5");delay(100);
                Wire.beginTransmission((0x40>>1));
                Wire.write(0x15);   
                Wire.write(0x00);
                Wire.endTransmission();
                
                client.println("Clear");delay(100);
            }
        }
    }
    else
    {
        client = server.available();
    }
}

void RtcInterrupt()
{
    client.println("RTC interrupt");
}

This application will hang as described when connected to the photon using telnet and pressing ‘c’.

Removing the line:

attachInterrupt(D3, RtcInterrupt, RISING);

Will cause the application to work as expected without hanging.

Does anybody have any input on this?

You are performing a possibly bigger task in an ISR than you probably should.

Having a heavy weight ISR might cause problems with other interrupt driven routines (e.g. I2C, TCPServer, TCPClient).

Try only setting a flag in your ISR and act upon the state of the flag inside loop().

BTW: There is an I2C issue being worked on, maybe this also contributes to your problem
Issue with I2C on Photon

Thanks for the reply.
The interrupt routine never gets executed. I can remove all code in the routine without any change in behaviour.

I have read that thread you mention but since the I2C works without problems when D3 is not set as interrupt i do not think the two problems are related.

Ok so I guess I am the only one to use this combination and thus seeing the problem since issue is very easy to reproduce.
Would it be more appropriate to ask in another thread if the cores are still produced?
They are marked as sold out but would fit my needs better since this bug is not present on the Core and the Core works better with chip antenna than the photon.

Cores are not produced anymore.
But if it is a bug (sorry no way to test myself) :particle: Particle will want to know about it, maybe you could file an issue on GitHub or ping (@) a :particle: Particle staff member like (mdma or BDub).

Thanks a lot I will find someone to ping about this.

I’ll be looking into this today, and look to release a hotfix when we resolve the issue.

Thank you very much that sounds great

Hey Loppen,

I’m getting a similar-ish problem:

I get the same cyan without breathing after a one or three loops.

@mdma Would appreciate any ideas you might have as well.

The code I’m using was working on earlier versions of the Core, but has now also stopped working since I updated my Core to 0.4.7, the Photon fares a little better with 0.4.7 by being able to run a couple loops before failing.

I’m not sure it is a good idea to call this a similar problem.
I mean the Photon can obviously hang under different circumstances like you experience (I have a few more examples of ways that I can make it hang most using I2C as well) but my example Is at least in my mind very easy to reproduce with a minimum amount of code.

Try simplifying your application to pinpoint that it is indeed I2C that makes it hang and if it is possible to simplify it even further to see what can make it work again.

I do believe that I2C can make the Photon hang under different circumstances but we should try to pinpoint problems as much as possible to help the developers.

Hey Loppen,

I thought I’d just feedback that my issue with the hanging Photon seems to be resolved with the new 0.4.9 firmware.

1 Like

Thanks a lot I will give it another try.