Hi i'm pretty new to the i2c world in arduino, i want to use an VL6180X sensor, but when executing Wire.begin() arduino freezes, and stops reading or writing from serial.
I have everything disconnected from arduino except for the sensor which is connected to 5V, GND and SCL and SDA pins.
I also tried to use the Adafruit_VL6180X library and freezes at same point vl.begin();
Thank you so much for your help
I have seen instances of wire.begin() hanging if the clock or data lines are LOW. Is there a pullup resistor on those lines?
This is the code that is executed in a Wire.begin() call:
// initialize state
twi_state = TWI_READY;
twi_sendStop = true; // default value
twi_inRepStart = false;
// activate internal pullups for twi.
// initialize twi prescaler and bit rate
TWBR = ((F_CPU / TWI_FREQ) - 16) / 2;
/* twi bit rate formula from atmega128 manual pg 204
SCL Frequency = CPU Clock Frequency / (16 + (2 * TWBR))
note: TWBR should be 10 or higher for master mode
It is 72 for a 16mhz Wiring board with 100kHz TWI */
// enable twi module, acks, and twi interrupt
TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWEA);
As you can see there is no loop the processor might be staying in endlessly. So I doubt that this call is really freezing even if the hardware is not properly built.
@SurferTim: As you can see the (weak) internal pullup is activated, so external pullups are only necessary for setups with a higher bus capacitance (p.e. longer bus length).
Post your complete code and a wiring diagram.