-
Notifications
You must be signed in to change notification settings - Fork 503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I2C (Wire) hangs when no device is attached. #241
Comments
Thanks for raising the issue, Can you specify the previous working version with your sketch. If possible could you give us the minimal version of your sketch that causes the issue, that will help me to quickly reproduce and troubleshoot. |
@hathach For the minimal sketch, here is a more reduced version of it:
The strange thing is that if I change the pins used for SDA and SCL it seems to work. On pins 25 and 26 is nothing connected than the sensor, the pins are open if the sensor is not attached. The I2C pullup resistors are on the sensor board, but I tried to add a pullup to the SDA pin when no sensor is connected, but it still hangs. |
Update: |
@hathach |
Unfortunately, I haven't got time to work on this yet |
Just in case you find time, another weird thing. Points into the direction that it has something todo with GPIO 26. But I have no idea why. |
bee, do you have i2c pullups on your board, even when no sensor is attached? |
@ladyada I tried just now to put 470Ohm resistors on the nRF52 board, so that both SDA and SCL are pulled up if no sensor is attached and then the I2C scan works. 🥇 ButWhy does the I2C scan work on the second I2C (GPIO 15 and GPIO 16) without pull-ups and without sensor attached? Using the pull-ups will be a solution for the final product we are working on, but right now we are using proto boards where the pull-ups are on the sensor board and not on the nRF52 Feather board. Will discuss with our HW guy how to solve this. |
the i2c spec says you must have pullups when using i2c, other behavior is not guaranteed. so add 10K pullups :) |
|
the pullups are very weak, dont rely on them |
Closing this issue because it might not be a SW problem, but a HW problem on the Adafruit nRF52 Feather board. Finally got one of my own proto-boards up and running:On this board there is no problem with the I2C if no sensor is attached. So I guess it must be a problem on the nRF52 Feather board. Testcode: #include <bluefruit.h>
#include <Arduino.h>
#include <Wire.h>
/** SDA pin for first I2C */
#define SDA0 PIN_WIRE_SDA // GPIO 25
/** SCL pin for first I2C */
#define SCL0 PIN_WIRE_SCL // GPIO 26
#define I2C_SPEED_STANDARD 100000
#define I2C_SPEED_FAST 400000
/** First sensor Wire class */
TwoWire i2cWire1 = TwoWire(NRF_TWIM0, NRF_TWIS0, SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn, SDA0, SCL0);
void setup(void)
{
Serial.begin(115200);
Serial.println("Initializing sensors");
// Scan the I2C interfaces for devices
byte error;
Serial.println("Start I2C #1");
i2cWire1.begin();
i2cWire1.setClock(I2C_SPEED_STANDARD);
Serial.println("Scan I2C bus #1");
for (byte address = 1; address < 127; address++)
{
Serial.print("Trying address: 0x");
Serial.println(address,HEX);
i2cWire1.beginTransmission(address);
error = i2cWire1.endTransmission();
if (error == 0)
{
Serial.print("Found device on I2C #1 on address ");
Serial.println(address, HEX);
}
}
i2cWire1.end();
}
void loop(void)
{
}```
Debug output: Initializing sensors BSP Library : 0.9.3
|
just to clarify - its not really a hardware issue with feather, i2c is just not specified to work without pullups, any extra capacitance on the lines will affect it. don't run i2c without pullups because this can always happen! :) |
The feather bords come with pullups according to this |
Feather microcontroller boards do not come with pullups by default. If there are on-board devices sharing the external I2C bus, then there will be pullups, but in general, Adafruit boards expect the I2C breakout boards to come with appropriate pullups. Quoting from the link above:
|
I have in my SW a simple I2C scan function to find device connected to the board. This function worked perfect before last update of this repo. If I found the devices I am looking for and the flags were set. If I didn't find the devices, the flags were not set. After that my software just continued and used the sensor that were found or gave an error message if no devices were found.
Since the last update of the repo, if there are no devices connected, the SW just hangs in the
i2cWire2.beginTransmission(address);
function and never returns from it.The weird thing is that it happens only on the I2C bus on pins 25 and 26. The second I2C bus on pins 15 and 16 works as expected.
And this behavior can be replicated on all my nRF52 feather boards that I have.
Any idea why? I didn't find commits that seem to change something in the Wire library.
Scan function:
Log output when no sensor is connected:
And after that no more output is given and the SW just hangs and doesn't response.
Log output when a sensor is connected:
The text was updated successfully, but these errors were encountered: