I2C with nRF connect using 52833dk

I am having trouble understanding where am I going wrong . I am using the devacadamy sample with the BME280 sensor and just trying to get the device id for starters . 

#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";
    };
};
 

Parents
  • Hello,

    Please elaborate further on what you mean when you say that you are 'going wrong' - what do you observe, and how does it diverge from what you would have expected?
    Does the code compile and flash without issues, but no readings happen? Does any function calls fail unexpectedly?
    What does the log say when this happens? Which pins is the sensor connected to on the device - is it the pins used for the i2c0 node, or could it perhaps be for the i2c1 node instead?
    The more relevant information you provide, the quicker it will be for us to help you resolve your issue.

    Looking forward to solving this issue together! :) 

    Best regards,
    Karl

Reply
  • Hello,

    Please elaborate further on what you mean when you say that you are 'going wrong' - what do you observe, and how does it diverge from what you would have expected?
    Does the code compile and flash without issues, but no readings happen? Does any function calls fail unexpectedly?
    What does the log say when this happens? Which pins is the sensor connected to on the device - is it the pins used for the i2c0 node, or could it perhaps be for the i2c1 node instead?
    The more relevant information you provide, the quicker it will be for us to help you resolve your issue.

    Looking forward to solving this issue together! :) 

    Best regards,
    Karl

Children
Related