Configuring i2c0 on nrf5340dk

Greetings

I am trying to configure the nrf5340dk to use the i2c0 bus. I believe i2c1 is already configured, but for learning purposes, I want to figure out how to do this. I have used the Ask-AI  and asked "how do I enable the i2c0 bus on the nrf5340dk", to which I receive an extensive answer, indicating I need to edit the DTS file and make a lot of additions. I gather this is an overlay file one would create?

I looked at the nordic developer academy, to which the process is much simpler in the sense that the prj.conf file is edited and the following code is added in an .overlay file:

&i2c0 {
    mysensor: mysensor@4a{
        compatible = "i2c-device";
        reg = < 0x4a >;
        label = "MYSENSOR";
    };
};

Afterwards all changes are made in main.c after getting the node identifier symbol.

My questions are:

1. Would I ever edit a .dtsi file? if so, must I create a .dtsi file? I've read, one should not edit Nordic's .dts file but create an .overlay for the .dts but there is no mention of the .dtsi.

2. Which of the 2 approaches above, are correct, from the Ask-AI and the developer academy? I followed the developer academy and got the following error "identifier "__device_dts_ord_127" is undefined".

Any help would be appreciated, please.

Thank you

Parents
  • The DTS is pulled (combined) from multiple sources, with the .overlay being the simplest method. You don't need to mess with dtsi files unless you want to define your own BOARD.

    Above dts overlay is missing a status = "okay"; statement, I believe I2C0 is not enabled by default (and will probably collide with one of the enabled uarts).

Reply
  • The DTS is pulled (combined) from multiple sources, with the .overlay being the simplest method. You don't need to mess with dtsi files unless you want to define your own BOARD.

    Above dts overlay is missing a status = "okay"; statement, I believe I2C0 is not enabled by default (and will probably collide with one of the enabled uarts).

Children
Related