Adding a peripheral to a project using BLE

I have a project that runs I2C to collect data from a pressure sensor and I have a different project that sends arrays of data over Bluetooth and they both work perfectly fine. Now I'm trying to add the I2C part to the Bluetooth project. I added I2C to the .overlay file and the prj.conf file however the function "device_get_binding" still returns a NULL pointer for I2C.

Can someone please tell me what am I missing or what am I doing wrong ?

Thank you in advance.

Parents
  • Hi,

    Could I see the .overlay file, prj.conf file, and the code where you call the device_get_binding() function?

  • Hello,

    I the bluetooth project I'm working on is the 'peripheral_uart' example to which I want to add the I2C code and send the data via Bluetooth.

    Here is the code in the .overlay file :

     {
    	soc {
    
                    &i2c1 {
                          status = "okay";
                          compatible = "nordic,nrf-twim";
                          label = "I2C_1";
                          sda-pin = <5>;
                          scl-pin = <4>;
                          clock-frequency = <400000>; 
                  };
    		/* Add a flash controller which has the compatible
    		 * 'zephyr,sim-flash'. This will ensure that the flash
    		 * simulator can use it. None of the other properties in this
    		 * node is used for anything.
    		 */
    		nordic_ram_flash_controller: nordic_ram-flash-controller@0 {
    			compatible = "zephyr,sim-flash";
    			reg = <0x00000000 DT_SIZE_K(40)>;
    			#address-cells = <1>;
    			#size-cells = <1>;
    			erase-value = <0xff>;
    			label = "nordic_ram_flash_flash_controller";
    
    			/* This node label must match that used in the flash
    			 * simulator.
    			 */
    			flash_sim0: flash_sim@0 {
    				status = "okay";
    				compatible = "soc-nv-flash";
    				label = "simulated_flash";
    				erase-block-size = <4096>;
    				write-block-size = <4>;
    				reg = <0x00000000 DT_SIZE_K(256)>;
    
    				partitions {
    					compatible = "fixed-partitions";
    					#address-cells = <1>;
    					#size-cells = <1>;
    
    					/* This partition must be defined for
    					 * MCUboot to find the partition ID
    					 * of the primary slot for image 1,
    					 * which is stored in this partition.
    					 */
    					slot2_partition: partition@0 {
    						label = "image-2";
    						reg = <0x00000000 0x00000A000>;
    					};
    				};
    			};
    		};
    	};
    };
    

    Here is the prj.conf :

    # Enable the UART driver
    CONFIG_UART_ASYNC_API=y
    CONFIG_NRFX_UARTE0=y
    CONFIG_SERIAL=y
    
    CONFIG_GPIO=y
    
    # Make sure printk is printing to the UART console
    CONFIG_CONSOLE=y
    CONFIG_UART_CONSOLE=y
    
    # Stacks and heaps
    CONFIG_MAIN_STACK_SIZE=16384
    CONFIG_HEAP_MEM_POOL_SIZE=16384
    
    # I2C
    CONFIG_I2C=y
    CONFIG_NRFX_TWIM=y
    CONFIG_NRFX_TWIM1=y
    
    # Rebooot
    CONFIG_REBOOT=n
    CONFIG_RESET_ON_FATAL_ERROR=n
    
    CONFIG_BT=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_DEVICE_NAME="Nordic_UART_Service"
    CONFIG_BT_DEVICE_APPEARANCE=833
    CONFIG_BT_MAX_CONN=1
    CONFIG_BT_MAX_PAIRED=1
    
    # Enable the NUS service
    CONFIG_BT_NUS=y
    
    # Enable bonding
    CONFIG_BT_SETTINGS=y
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_FLASH_MAP=y
    CONFIG_NVS=y
    CONFIG_SETTINGS=y
    
    # Enable DK LED and Buttons library
    CONFIG_DK_LIBRARY=y
    
    # This example requires more workqueue stack
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    
    # Config logger
    CONFIG_LOG=y
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=y
    CONFIG_LOG_BACKEND_UART=n
    
    CONFIG_ASSERT=y
    

    I am calling the device_get_binding() function in main() :

        const struct device *i2c_dev;
    
        i2c_dev = device_get_binding("I2C_1");
        
        if (i2c_dev==NULL) printk("I2C_Driver NOT Found\n");
    
        else  printk("I2C_Driver Found\n");

    I am probably doing something wrong

  • In your overlay file, try moving the " &i2c1 {}; " outside the other brackets:

    {
        soc {
        
            ...
        
        };
    };
    
    &i2c1 {
        ...
    };

Reply Children
Related