9 years, 10 months ago.

I2C does not work when Serial debug is on

Initial question at Dec-31, 2014

Yesterday I used the mbed library, revision 92:4fc01daae5a5. It was fine for me to read a temperature data from an HTU21D i2c sensor device. This time, I assigned the P0_4 to the SDA and the P0_5 to the SCL.

But the default i2c pin assign, P0_10: SDA and P0_8: SCL, is a little bit strange. When the statement of "Serial pc(USBTX, USBRX);" is executed, the i2c does not work. Also the pc.printf function does not work too.

Self follow at Feb-1, 2015

The cause of this problem is confliction of pin selection in mbed library. Isn't it? The constructer of the Serial class calls the serial_init function in the serial_api.c which is in "/mbed/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/". In this function, uart pins are set as follows:

   obj->uart->PSELRTS = RTS_PIN_NUMBER;
   obj->uart->PSELTXD = tx; //TX_PIN_NUMBER;
   obj->uart->PSELCTS = CTS_PIN_NUMBER;
   obj->uart->PSELRXD = rx; //RX_PIN_NUMBER;

I don't know why the RTS and CTS pins are selected in this function.

The RTS(P0_8) and the CTS(P0_10) conflict with the I2C_SCL0 and the I2C_SDA0, therefor the I2C function does not work correctly, I think.

Question relating to:

BLE Nano is the smallest Bluetooth 4.1 Low Energy (BLE) development board in the market. The core is Nordic nRF51822 (an ARM Cortex-M0 SoC plus BLE capability) running at 16MHz …

2 Answers

9 years, 9 months ago.

The best place for this to get noticed is probably a github bug report: https://github.com/mbedmicro/mbed, or if you want you can also submit a pull request there to fix it. I don't know if these lines are actually the issue, or a little bit earlier:

    NRF_GPIO->DIR |= (1 << tx); //TX_PIN_NUMBER);
    NRF_GPIO->DIR |= (1 << RTS_PIN_NUMBER);
 
    NRF_GPIO->DIR &= ~(1 << rx); //RX_PIN_NUMBER);
    NRF_GPIO->DIR &= ~(1 << CTS_PIN_NUMBER);

Thank you for your suggestions.

posted by Takashi Ishizaki 01 Feb 2015
9 years, 9 months ago.

I am not sure why CTS/RTS needs to be set in serial_init. I tested with the following two changes to the mbed library. I was able to concurrently use p10/p8 for i2c and p9/p11 for serial.

mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/TARGET_/device.h

#define DEVICE_SERIAL           1
#define DEVICE_SERIAL_FC        1

and

mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/serial_api.h

    // in serial_init
...
    //pin configurations -- Delete RTS/CTS references
    NRF_GPIO->DIR |= (1 << tx); //TX_PIN_NUMBER);
    NRF_GPIO->DIR &= ~(1 << rx); //RX_PIN_NUMBER);
...
    obj->uart->PSELTXD = tx; //TX_PIN_NUMBER;
    obj->uart->PSELRXD = rx; //RX_PIN_NUMBER;
    obj->uart->PSELRTS = 0xFFFFFFFF; // Disable RTS
    obj->uart->PSELCTS = 0xFFFFFFFF; // Disable CTS