9 years, 4 months ago.

Arch BLE: I2C working?

I need help to get the I2C digital interface working with this board.

According to the Nordic chip specs, the chip supports I2C. The Arch BLE pinout shows SDA and SLC on P5 and P6, which is promising.

However, this line of code causes a crash.

printf("Creating i2c interface ...\r\n"); I2C ic(p5, p6); I2C (pin sda, pin slc)

See a small test program for the Seed Studio Barometer sensor at: http://developer.mbed.org/users/grassel/code/Seeed_Barometer_Sensor_Example/file/e15e9cb70711/main.cpp

Question relating to:

Arch BLE is an mbed enabled development board based Nordic nRF51822. With Arduino form factor and Grove connectors, it is extremely easy to create a bluetooth low energy device.

4 Answers

9 years, 4 months ago.

I have not yet tested I2C on the nRF, but are you sure you compile for the right target. The p5,p6 pinnames may be wrong/illegal for other targets. Have you tested with hardcoding the pinnames (P0_5, P0_6). Have you tested without the instantiation of the BMP device, maybe the code crashes when this device can not be found.

9 years, 4 months ago.

Hi Guido,

Thanks for reporting the issue. The mbed lib sets p13 and p22 to SDA, p15 and p20 to SCL, but all the digital I/Os of nRF51822 can be used SCL and SDA. We can use thembed-src and change some code to disable this restriction. find mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/i2c_api.c

Change the following code:

// determine the SPI to use
    I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
    I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
    I2CName i2c     = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
    obj->i2c = (NRF_TWI_Type *)i2c;
 
    MBED_ASSERT((int)obj->i2c != NC);

to

    obj->i2c = (NRF_TWI_Type *) I2C_1;

I will try to find a way to solve the issue in the mbed lib.

Hello and thank you Yihui Xiong for your quick response. Unfortunately, I am still stuck.

I followed your instructions to comment out lines and add the new line to use I2C_1. This is supposed to work with p13 as SDA, and p15 as SCL, correct? My Seed Arch BLE v1.0 board does not have a pin P15! Where the pinout (see http://developer.mbed.org/platforms/Seeed-Arch-BLE/) shows p15, the label on my board says p18! - Could there be several (incl. a faulty) revisions of the board? I tried nevertheless, connected SCL to p18, but had not success.

Is there another I2C interface besides I2C_1 that I could use? Note, my board does not have mentioned pin p20 either!

I have published my changes, including modified mbed-src at http://developer.mbed.org/users/grassel/code/Seeed_Barometer_Sensor_Example/

Quiet confused. - I would appreciate greatly if you still had some advise for me.

posted by Guido Grassel 03 Nov 2014

Hi Guido,

After changing the mbed-src library, we can use any digital I/Os as SCL and SDA. For example:

    printf("Creating i2c interface  ...\r\n");
    I2C ic(p29, p28); // I2C (pin sda, pin slc); // use a Grove connector
    printf("Creating barometer interface  ...\r\n");
    BMP085 barometer(ic, BMP085_oss1);
posted by Yihui Xiong 04 Nov 2014

Thank you very much again. With the latest explanations, I get the example to work. Code published at http://developer.mbed.org/users/grassel/code/Seeed_Barometer_Sensor_Example/

posted by Guido Grassel 04 Nov 2014
9 years, 4 months ago.

Hi,

I created this library as a workaround until the mbed library supports this: http://developer.mbed.org/users/jaerts/code/I2CX/docs/9d9fc94594e3/classmbed_1_1I2CX.html

No need to modify any mbed source code, and it should work with any pin as you normally expect it.

Hope this helps

Thank you very much, Joris Aerts, I also got your solution to work, published at http://developer.mbed.org/users/grassel/code/Seed_Barometer_Sensor_custom_I2C_lib/

Since my simple application passes the i2c object to the BMP085 Seed barometer library, using your I2CX library replacement requires a simple patch to that library. So, the choice is between patching mbed-src and patching the BMP085 lib in my case.

posted by Guido Grassel 04 Nov 2014

Reading the source code of your I2CX and comparing to I2C of mbed, would it be feasible to define I2CX as a subclass of I2C, and to add a new constructor with the additional I2CName peripheral parameter? - Such design would allow use of unmodified library using I2C, like in my case:

I2CX ic(I2C_0, p29, p28); BMP085 barometer(ic, BMP085_oss1);

posted by Guido Grassel 04 Nov 2014

This is what I planned to do, but unfortunately c++ does not allow overriding the constructor of the parent class (unless I'm mistaken), so this it not possible.

My suggestion is to merge this into the mbed library, making the peripheral parameter optional, so it doesn't break any existing code. I might do a pull request to mbed-src this week if I can find some time.

posted by Joris Aerts 04 Nov 2014
8 years, 7 months ago.

Any ideas on how to convert arduino libraries to use I2CX ? I want to use BMP180 + HTU21D + MPU6050 + SI1145, it works perfectly fine on the same bus on arduino, but i don't manage to make that sensors working at the same time with Arch BLE.