Using both TWIM instances not work on certain pins

Hi,

I noticed weird behaviour while using TWIM0 and TWIM1.

My setup is : 

  • nrf52dk 
  • NRF Connect SDK v1.8.0
  • SPI2 works with SDMMC driver to handle the sd card
  • TWIM1 handle the OLED SSD1306
  • TWIM0 handle the VL6180x

I am working directly on nrfx drivers.

I 've got TWIM1 instance configured on pins P0.27(SCL), P0.28(SDA). That instance works correctly, both lines are pulled high by internal pull-up resistors, and the whole communication with my external OLED works great. 

In my setup I have to use the TWIM0 instance also. That instance is configured on pins P0.31(SCL), P0.30(SDA) but in that case both lines are hold low at level of 20mV. 

I decided to simply change the TWIM0 pins to P0.03(SCL), P0.04(SDA). In that configuration lines are pulled high and the I2C communication works correctly.

I double checked the nrf52dk layout to check if P0.31 and P0.30 are used in another way by the board, but it seems that they are directly connected from the header to nrf52832 pads. 

I am aware of shared resources of peripheral instances but in that configuration it doesn't occur.

What am I missing ? 

What could cause that behaviour ? 

Thanks you in advance,

  • Hi

    I think you should disable spi1

    &spi1 {
        //compatible = "nordic,nrf-spi";
        status = "disabled";
        //sck-pin = <31>;
        //mosi-pin = <30>;
        //miso-pin = <29>;
    };

  • I am sorry. I forgot to mention that I edited the nrf52dk default .dts file. Right now it looks like this : 

    /*
     * Copyright (c) 2017 Shawn Nock <[email protected]>
     * Copyright (c) 2017 Linaro Limited
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
     /dts-v1/;
     #include <nordic/nrf52832_qfaa.dtsi>
     
     / {
    	 model = "Nordic nRF52 DK NRF52832";
    	 compatible = "nordic,nrf52-dk-nrf52832";
     
    	 chosen {
    		 zephyr,console = &uart0;
    		 zephyr,shell-uart = &uart0;
    		 zephyr,uart-mcumgr = &uart0;
    		 zephyr,bt-mon-uart = &uart0;
    		 zephyr,bt-c2h-uart = &uart0;
    		 zephyr,sram = &sram0;
    		 zephyr,flash = &flash0;
    		 zephyr,code-partition = &slot0_partition;
    	 };
     
    	 aliases {
    	 };
     };
     
     &adc {
    	 status = "okay";
     };
     
     &gpiote {
    	 status = "okay";
     };
     
     &gpio0 {
    	 status = "okay";
     };
     
    &uart0 {
    	 status = "okay";
    	 compatible = "nordic,nrf-uarte";
    	 current-speed = <115200>;
    	 tx-pin = <6>;
    	 rx-pin = <8>;
    	 rts-pin = <5>;
    	 cts-pin = <7>;
     };
     
     &spi2 {
    	 compatible = "nordic,nrf-spi";
    	 status = "okay";
    	 sck-pin = <25>;
    	 mosi-pin = <23>;
    	 miso-pin = <24>;
     };
    
    
    
     &flash0 {
     
    	 partitions {
    		 compatible = "fixed-partitions";
    		 #address-cells = <1>;
    		 #size-cells = <1>;
     
    		 boot_partition: partition@0 {
    			 label = "mcuboot";
    			 reg = <0x00000000 0xc000>;
    		 };
    		 slot0_partition: partition@c000 {
    			 label = "image-0";
    			 reg = <0x0000C000 0x32000>;
    		 };
    		 slot1_partition: partition@3e000 {
    			 label = "image-1";
    			 reg = <0x0003E000 0x32000>;
    		 };
    		 scratch_partition: partition@70000 {
    			 label = "image-scratch";
    			 reg = <0x00070000 0xa000>;
    		 };
    		 storage_partition: partition@7a000 {
    			 label = "storage";
    			 reg = <0x0007a000 0x00006000>;
    		 };
    	 };
     };
     

    So, my P0.31 and P0.30 are not overridden by SPI1. 

    This is how my prj.conf looks like : 

    # GPIO
    CONFIG_GPIO=y
    CONFIG_NRFX_GPIOTE=y
    # ADC
    CONFIG_ADC=n
    CONFIG_NRFX_SAADC=y
    # SPI-SD-MMC 
    CONFIG_SPI=y
    CONFIG_DISK_ACCESS=y
    CONFIG_DISK_DRIVERS=y
    CONFIG_DISK_DRIVER_SDMMC=y
    CONFIG_FILE_SYSTEM=y
    CONFIG_FAT_FILESYSTEM_ELM=y
    # Increase stack size to handle the FAT FS
    CONFIG_MAIN_STACK_SIZE=2048
    # TWI
    CONFIG_NRFX_TWIM=y
    CONFIG_NRFX_TWIM0=y
    CONFIG_NRFX_TWIM1=y
    # LOGGING
    CONFIG_PRINTK=y
    # ENABLE ZEPHYR SYSTEM LOGGER
    CONFIG_LOG=y
    CONFIG_LOG_BACKEND_RTT=y

  • Actually you should not change the origin DTS file. You have to create DTS .overlay file in the folder /board/yourBoard.overlay in your project. And you can overwrite some settings you need. And please disable spi1)

  • Hello, 

    Thank u for your help. I disabled the spi1 in device tree. That did not help.

    I also disabled the spi0, but that didn't solve the problem.

    Have you got any other ideas what can I check ?

    The voltages at those pins are still in range 20mV -50mV

  • When I set P0.31 to be SDA line, and P0.30 to be SCL (invesrion).I have got SCL line pulled high but SDA line is still low. What can cause that weird behaviour ? 

Related