nrf52840 i2c Error on I2C line occurred for message 0

I am struggling with an error for some time now.

We are transitioning from the NRF5 SDK to nrfConnect but the i2c connection to our vcnl4035 sensors only works sometimes.

I am getting this error when the sensor tries to initialise. I wrote the [sensor driver](https://github.com/felixbaral/zephyr_vcnl4035) myself (i mostly copied the code of the vcnl4040 from zephyr).

```

<dbg> vcnl4035: vcnl4035_init: vcnl4035_init
<err> i2c_nrfx_twim: Error on I2C line occurred for message 0
<err> vcnl4035: some error while reading: -5

```

The strange thin is that it works flawlessly when i first flash the old nrf5 SDK firmware and the flash the zypher code. If I `recover` the chip and then flash the zephyr code i am getting the above error.

It even works when I just flash the old firmware without running it. How can that be?

My devicetree entry looks like this:

```

&i2c1 {
status = "okay";
pinctrl-0 = <&i2c1_default>;
pinctrl-1 = <&i2c1_sleep>;
pinctrl-names = "default", "sleep";

irtop: vcnl4035@60 {
compatible = "vishay,vcnl4035";
label = "irtop";
reg = <0x60>;
led-current = <200>;
led-duty-cycle = <40>;
proximity-it = "1";
proximity-trigger = "close";
als-it = <640>;
ired-select = <0>;
};
};
...
i2c1_default: i2c1_default {
group1 {
psels = <NRF_PSEL(TWIM_SDA, 0, 9)>, <NRF_PSEL(TWIM_SCL, 0, 11)>;
};
};

```

I hooked up a logic analyzer and the offending i2c line looks like this: (but i ight redo these measurements)

Any ideas?

Parents
  • Hello

    sensors only works sometimes

    If it works sometimes then you may check the hardware (it is correct / good / functional, properly powered) and the connections to the I2C pins you are using.

    The strange thin is that it works flawlessly when i first flash the old nrf5 SDK firmware and the flash the zypher code. If I `recover` the chip and then flash the zephyr code i am getting the above error.

    What pin configurations you are using in the nrf5 sdk? What / how they are different from the one you are using now?

    psels = <NRF_PSEL(TWIM_SDA, 0, 9)>, <NRF_PSEL(TWIM_SCL, 0, 11)>;

    can you change the pins and check again?

    On the DK, P0.9 is by default used as an NFC pin. 

  • If it works sometimes then you may check the hardware (it is correct / good / functional, properly powered) and the connections to the I2C pins you are using.

    The hardware appears to be fine because it works all the time on the old firmware. I am working on production hardware.

    The pin configuration on the nrf5SDK is the following:

    static void twi_init(nrf_drv_twi_t* pTwiInstance, unsigned int scl, unsigned int sda)
    {

    const nrf_drv_twi_config_t twi_config =
    {
    .scl = scl,
    .sda = sda,
    .frequency = NRF_TWI_FREQ_400K,
    .interrupt_priority = APP_IRQ_PRIORITY_LOW,
    .clear_bus_init = true
    nrf_drv_twi_uninit(pTwiInstance);

    ret_code_t err_code = nrf_drv_twi_init(pTwiInstance, &twi_config, 0, NULL);
    APP_ERROR_CHECK(err_code);

    nrf_drv_twi_enable(pTwiInstance);
    }
    But I kinda found how to fix it but are not yet fully there.
    Maybe you can explain: I did compare the UICR when it does work and when it doesn't.
    Turns out that there only was one difference, and when I copy over that one byte
    it does work.
    The command nrfjprog -f nrf52 --log --memrd 0x1000120C returns
    0x1000120C: FFFFFFFF if it is not working and
    0x1000120C: FFFFFFFE if it is working.
    What is that UICR address? How can I configure it?
  • Hello,

    Good to know that you made progress.

    As previously, the pin P0.09 is by default used as an NFCT pin, so if you want to configure it as a gpio, you need to do this (as below):

    previously, we would use the CONFIG, but in the latest SDK, as described, we need to use the devicetree to configure NFCT pins for GPIO. For that, we can add the following in the device-overlay

    &uicr { nfct-pins-as-gpios; };

    Coming to your question, all UICR addresses are mentioned in the product specification. The base address of UICR on nrf52840 is 0x10001000,

    and the address 0x20C is for setting pins for NFC

    You can see that if the LSb is 0 then the pin is used as GPIO, and if it is 1 then it is an NFC pin.

    /BR, Naeem

  • Thanks for the answer. I solved it with that help.

    Though the strange thing is that, as said, i am not using the DK but am working on production hardware and we don't have any nfc stuff enabled.

    To set that flag i had to enable it. I did it as follows:

    CONFIG_NFCT_PINS_AS_GPIOS=y in my prj.conf
    and
    &nfct {
    compatible = "nordic,nrf-nfct";
    /delete-property/ status;
    status = "okay";
    };
    in my devicetree. But as said, just to then use that flag.
    Is it a bug?
    Beste Wishes
Reply
  • Thanks for the answer. I solved it with that help.

    Though the strange thing is that, as said, i am not using the DK but am working on production hardware and we don't have any nfc stuff enabled.

    To set that flag i had to enable it. I did it as follows:

    CONFIG_NFCT_PINS_AS_GPIOS=y in my prj.conf
    and
    &nfct {
    compatible = "nordic,nrf-nfct";
    /delete-property/ status;
    status = "okay";
    };
    in my devicetree. But as said, just to then use that flag.
    Is it a bug?
    Beste Wishes
Children
Related