Weird I2C Issue

I’ll preface this by saying I wasn’t sure if i should post this here or in Programming questions, but decided to post it here because the issue only happens on the Nano Every.

I’ve been asked to Customize / update some existing code (made for the Nano V3) for a Tank Level sensor , to work on the Nano Every, it seemed simple enough, except i’ve now reached the limit where i think i’ve stared myself blind trying to find the issue.

The code works like it should, until an I2C request is made, after which it stalls at some point, at first it would stall right after printing out the “RequestID” Val (Line 98) to Serial, i fiddled a bit and tried commenting out the 50ms delay right after, after which the code would progress a bit, but still stall, this time after printing out “ByteID +1” (Line 143).

The nano every works as an I2C Slave, but both it & the I2C master (an Arduino Uno R3) will stall, doing nothing until the I2C connection is broken, after which the Uno will continue on as normal.
The code works almost as is (with the exception of ‘wdt_enable()’ at line 47/48) when run on a Nano V3, so the issue has to lie with the Nano Every, but i just can’t seem to figure out why.

So now i’ve come to ask you guys for help.
So thank you in advance, any and all help/advice is greatly appreciated.

I2C_TankSensor_NanoEvery.ino (7.76 KB)

Tidy up your sketch code. Then someone will probably look at it. They might even run on real hardware and debug it for you.

David.

Are you sure the hardware is OK? I2C requires pull-up resistors. Do you have an oscilloscope to have a look at the signals?

I would write a very simple test sketch to test the I2C first. If that works you can look at application level debugging on your full sketch.

david_prentice:
Tidy up your sketch code. Then someone will probably look at it. They might even run on real hardware and debug it for you.

Not entirely sure what you mean by tidying it up, constructive criticism would be more useful than whatever that comment was supposed to be.

Klaus_K:
Are you sure the hardware is OK? I2C requires pull-up resistors. Do you have an oscilloscope to have a look at the signals?

I would write a very simple test sketch to test the I2C first. If that works you can look at application level debugging on your full sketch.

Hardware side of things should be okay, I'm sure of everything except for the Nano Every board.
I'll do some simpler I2C tests today, and reply back if/when i come to any conclusions on that.

After a little bit of further testing it seems that the Nano Every only works as long as it is the I2C Master, but not when set as an I2C Slave, which arguably doesn't help me much, but it might help narrow down the issue for others.

I attempted to check the I2C Clock via oscilloscope, but wasn't able to get anywhere, i blame my subpar oscilloscope skills for that one, and i don't have any equipment capable of analyzing the data signal.

"Tidy up" was intended to be constructive. You generally discover your errors during the "tidying" process.

But more importantly, attractive and readable code encourages members to read and possibly participate.

Yes, it would be a very interesting subject if the Wire Slave does not work properly.
Post a simple example to illustrate the failure. I guarantee that you will get help.

David.

david_prentice:
Yes, it would be a very interesting subject if the Wire Slave does not work properly.
Post a simple example to illustrate the failure. I guarantee that you will get help.

Set up two quick sketches, a master and a slave sketch, wherein both master and slave will try to Transmit and Receive a Value, as before when working as the slave, the Nano Every board will hang up once it has gotten a request, however it also does not seem to receive anything.

When it functions as Master, it can Request and Receive seemingly without issue, however it doesn’t seem to Transmit anything, i believe it was mentioned elsewhere on the Forum that it had problems with ‘Wire.endTransmission()’, so that might be the culprit for that one.

The sketches have both been tested to work on two Uno boards, aswell as an older Nano V3 board, on which they work without issue for me.

I2C_TestEvery_Master.ino (850 Bytes)

I2C_TestEvery_Slave.ino (812 Bytes)