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

  • Hi again, Divya!

    Add the following to your prj.conf: 

    CONFIG_NFCT_PINS_AS_GPIOS=y

    With fairly low I2C frequency it should work fine! 

    Best regards,
    Carl Richard

  • Hi Carl!

    I added "CONFIG_NFCT_PINS_AS_GPIOS=y" in "prj.conf" and 

    sda-pin = < 3 >;//P0.3
    scl-pin = < 2 >;//P0.2

    in "nrf5340pdk_nrf5340_cpuapp.overlay".   However, i2c_transfer fails as follows:

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

    Is there any other change required?

    Regards,

    Divya B M

  • Hello, again!

    How does your prj.conf look? 

    The following are my I2C settings, see if yours match.

    prj.conf:

    # I2C
    CONFIG_I2C=y
    CONFIG_I2C_NRFX=y
    CONFIG_I2C_1=y
    CONFIG_NRFX_TWIM1=y
    
    CONFIG_NFCT_PINS_AS_GPIOS=y

    nrf5340pdk_nrf5340_cpuapp.overlay:

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

    main.c (extract):

    void main(void)
    {
    	printk("The I2C test started\n");
        struct device *i2c_dev;
    	int error;
    
        i2c_dev = device_get_binding("I2C_1");
        if (!i2c_dev) {
            printk("Binding failed.");
            return;
        }
        i2c_configure(i2c_dev, I2C_SPEED_SET(I2C_SPEED_STANDARD));
        
    //(...) 
    }


    Best regards,
    Carl Richard

  • Hi Carl!

    You are correct. Everything is the same except for nrf5340pdk_nrf5340_cpuapp.overlay:

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

    Regards,

    Divya

  • Hello again!

    I miswrote when I said I got it to work with pins P0.02 and P0.02. The DK requires some modifications to support the NFC pins as conventional GPIOs, as described below:

    "Pins W1 and AA1 are by default configured to use the NFC antenna, but if they are needed as normal GPIOs, R43 and R46 must be NC and R42 and R45 must be shorted by 0R."

    This is described here

    Best regards,
    Carl Richard 

Reply Children
No Data
Related