This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

change sda and scl pin for i2c1 on nrf5340

Hi,

I am using i2c driver available with zephr as i2c master. This is working fine.

I want to change the pins to P0.02 for SCL and P0.03 for SDA. I see multiple questions on similar line that indicates that this configuration should be possible.

However, when I try, the i2c transfer() call is getting stuck.

Since i2c driver from zephyr just binds to an existing i2c device, i am changing the sda and scl pin for i2c1 in "nrf5340pdk_nrf5340_cpuapp_common.dts" file. Let me know if i am missing any setting.

Regards,

Divya

 

Parents
  • Hello, Divya!

    The pins P0.02 and P0.03 are dedicated to NFC on the DK, so using them could yield erroneous behavior. According to the nRF5340 documentation pin P1.2 and P1.3 should be suitable for TWI.
    I also want to add tht recommend using an overlay when configuring peripherals in NCS. You can just add the file nrf5340pdk_nrf5340_cpuapp.overlay in your project directory, with the following contents: 

    &i2c1 {
    	status = "ok";
    	compatible = "nordic,nrf-twim";
    	sda-pin = < 33 >;
    	scl-pin = < 34 >;
        clock-frequency = <I2C_BITRATE_STANDARD>;  
    };

    Make sure that Prj.conf is configured correctly aswell.

    Let me know if this works for you or not.

    Best regards,
    Carl Richard

  • Hi Carl!

    Thanks for the quick response. 

    You can just add the file nrf5340pdk_nrf5340_cpuapp.overlay in your project directory

    I tried this. I see that the value reflects correctly in "devicetree_unfixed.h" generated file as follows: 
    #define DT_N_S_soc_S_peripheral_50000000_S_i2c_9000_P_sda_pin 33
    #define DT_N_S_soc_S_peripheral_50000000_S_i2c_9000_P_scl_pin 34

    However, when i make the corresponding connections, i2c_transfer fails as follows:

    " <err> i2c_nrfx_twim: Error 195952641 occurred for message".

    My prj.conf file is:
    CONFIG_I2C=y
    CONFIG_I2C_1=y
    CONFIG_SENSOR=y

    Am i missing something else? Any help with this will be useful. Thanks in advance!

    Regards,

    Divya B M

  • Hello, Divya!

    Could you try to add the following to your prj.conf:

    CONFIG_NRFX_TWIM1=y
    CONFIG_I2C_NRFX=y


    Hope that will work!

    Best regards,
    Carl Richard

Reply Children
Related