BME280 with nRF Connect SDK for the nRF52833 board.

I am having a lot of trouble having to change my dt files and receive errors every time i try to run a basic sample for the NCS . Is there any 'How to' that i can refer and build my solution

Parents
  • Hello Manas,

    In order to get familiar with NCS I would recommend you to take a look at out DevAcademy.

    Regards,

    Elfving

  • #include <zephyr.h>
    #include <device.h>
    #include <devicetree.h>
    #include <drivers/i2c.h>
    #include <sys/printk.h>
    
    #define BME280_ID_REG					0xD0
    
    #define I2C0_NODE DT_NODELABEL(mysensor)
    
    uint8_t id_read[1] ;
    
    void main(void)
    {
    
    	static const struct i2c_dt_spec dev_i2c = I2C_DT_SPEC_GET(I2C0_NODE);
    	
    	if (!device_is_ready(dev_i2c.bus)) {
    		printk("I2C bus %s is not ready!\n\r",dev_i2c.bus->name);
    		return;
    	}
    
    	uint8_t id_write[1] = {BME280_ID_REG};
    	
    	while (1)
    	{
    		i2c_write_read_dt(&dev_i2c,&id_write[0],1,&id_read[0],1);
    		printk("%d\n",id_read[0]);
    	}
    }
    
    
    
    ----------------------------------------------------------------------------------------------------------
    overlay file
    
    &i2c0 {
        
        mysensor: mysensor@76{
            compatible = "bosch,bme280";
            reg = < 0x76 >;
            label = "MYSENSOR";
        };
    };

    I am referring that only , and as a first step I am just trying to get the ID . I am not receiving any ID value.

Reply
  • #include <zephyr.h>
    #include <device.h>
    #include <devicetree.h>
    #include <drivers/i2c.h>
    #include <sys/printk.h>
    
    #define BME280_ID_REG					0xD0
    
    #define I2C0_NODE DT_NODELABEL(mysensor)
    
    uint8_t id_read[1] ;
    
    void main(void)
    {
    
    	static const struct i2c_dt_spec dev_i2c = I2C_DT_SPEC_GET(I2C0_NODE);
    	
    	if (!device_is_ready(dev_i2c.bus)) {
    		printk("I2C bus %s is not ready!\n\r",dev_i2c.bus->name);
    		return;
    	}
    
    	uint8_t id_write[1] = {BME280_ID_REG};
    	
    	while (1)
    	{
    		i2c_write_read_dt(&dev_i2c,&id_write[0],1,&id_read[0],1);
    		printk("%d\n",id_read[0]);
    	}
    }
    
    
    
    ----------------------------------------------------------------------------------------------------------
    overlay file
    
    &i2c0 {
        
        mysensor: mysensor@76{
            compatible = "bosch,bme280";
            reg = < 0x76 >;
            label = "MYSENSOR";
        };
    };

    I am referring that only , and as a first step I am just trying to get the ID . I am not receiving any ID value.

Children
Related