I2C scan works on nRF54L15DK but not on custom board

I am trying to scan for sensors on an I2C bus using the nrf54L15 and Zephyr RTOS. I modified the i2c example from here: https://github.com/iFransL/i2c-scanner/tree/main

I ran the code sample on the nRF54L15 DK. Everything works perfectly and I am able to detect devices on the bus. I wanted to run the same code sample on my custom board. But I couldn't get it to work. 

  • On the nRF54L15DK, I was using i2c port i2c21 and the pins 11 and 12 of GPIO port 1. Everything works perfectly
  • On my custom board, I am using i2c port i2c21 and the pins 0 and 1 of GPIO port 2. I am not able to detect any devices on the I2C bus.

Since my custom board has a connector to connect external sensors, I tried connecting the I2C bus on the custom board to the nRF54L15 DK. The DK can detect sensors on my custom board.

It definitely has to do with configuration of the I2C bus on my custom board. How can I troubleshoot this problem? Any help is appreciated. 

#define I2C_NODE DT_NODELABEL(my-i2c)

int main(void)
{
    const struct device *dev;
    dev = DEVICE_DT_GET(DT_NODELABEL(i2c21));  
    if (!device_is_ready(dev)) {
        return -1;
    }

    
	
	uint8_t error = 0u;
	uint8_t dst;
	uint8_t i2c_dev_cnt = 0;
	struct i2c_msg msgs[1];
	msgs[0].buf = &dst;
	msgs[0].len = 1U;
	msgs[0].flags = I2C_MSG_WRITE | I2C_MSG_STOP;

    while(1){

        printk("\n    | 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f |\n");
	    printk(  "----|---------------------------------------------------------------------------------");
       

        for (uint16_t x = 0; x <= 0x7f; x++) {
            /* New line every 0x10 address */
            if (x % 0x10 == 0) {
                printk("|\n0x%02x| ",x);	
            }
            /* Range the test with the start and stop value configured in the kconfig */
            if (x >= 8 && x <= 127)	{	
                /* Send the address to read from */
                error = i2c_transfer(dev, &msgs[0], 1, x);
                    /* I2C device found on current address */
                    if (error == 0) {
                        printk("0x%02x ",x);
                        i2c_dev_cnt++;
                    }
                    else {
                        printk(" --  ");
                    }
            } else {
                /* Scan value out of range, not scanned */
                printk("     ");
            }
            k_sleep(K_MSEC(100));
        }
        printk("|\n");
        printk("\nI2C device(s) found on the bus: %d\nScanning done.\n\n", i2c_dev_cnt);
        printk("Find the registered I2C address on: https://i2cdevices.org/addresses\n\n");
        

    }

    


    return 0;
}

&i2c21 {
    status = "okay";
    pinctrl-0 = <&i2c21_default>;
    pinctrl-1 = <&i2c21_sleep>;
    pinctrl-names = "default", "sleep";
};  
&pinctrl {
    /omit-if-no-ref/ 
    i2c21_default: i2c21_default {
        group1  {
            psels = <NRF_PSEL(TWIM_SCL, 2, 1)>,
                    <NRF_PSEL(TWIM_SDA, 2, 0)>;
        };
    };  
    /omit-if-no-ref/ 
    i2c21_sleep: i2c21_sleep {
        group1  {
            psels = <NRF_PSEL(TWIM_SCL, 2, 1)>,
                    <NRF_PSEL(TWIM_SDA, 2, 0)>;
            low-power-enable;
        };
    };
};
   

Parents Reply Children
No Data
Related