I2C not working on Nano2 in Arduino and Apache mynewt


#1

Hi,

I have been trying to connect a single I2C slave device (Sparkfun LIS3DH) to BLE Nano 2 for third day now without success.

Below code outputs only:

Ready!
After begin!

Source code:

#include "Wire.h"
#define I2C_ADDRESS 0x19

void setup() {
Serial.begin(9600);

uint8_t result;
uint8_t numBytes = 1;
// put your setup code here, to run once:

//Spin for a few ms
volatile uint8_t temp = 0;
for( uint16_t i = 0; i < 10000; i++ )
{
  temp++;
}

Serial.println("Ready!");

Wire.begin();

Serial.println("After begin!");

Wire.beginTransmission(I2C_ADDRESS);
Wire.write(0x0F); // WHO AM I
if( Wire.endTransmission() != 0 )
{
  Serial.println("Wire.endTransmission != 0");
}
Serial.println("After endTransmission");
Wire.requestFrom(I2C_ADDRESS, numBytes);
while ( Wire.available() ) // slave may send less than requested
{
  result = Wire.read(); // receive a byte as a proper uint8_t
}

Serial.print("\nWire.read: ");
Serial.print(result, HEX);
}

void loop() {
  // put your main code here, to run repeatedly:
}`

On Apache mynewt the hal_i2c_master_read/write functions just timeouts.

I have tested above code on Arduino Uno and got the correct 0x33 in response:

Ready!
After begin!
Wire read: 0x33

I also connected 10k pull-up resistors for SCL and SDA but to no avail. It looks like there are already pull-ups on the back-side of Nano 2.

Please advise as I’m really confused by the fact that I2C is not working on Nano 2.


#2

I have the same issue. :frowning:


#3

@matanshapira, switch to Apache Mynewt. The learning curve is steep but you have 100% control over the software. The whole bootloader + app is open-sourced.

I was able to run I2C on it flawlessly.