Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

merging 2 or 3 i2c devices using NRF5340dk

Hello everybody,
i succeeded to get the output from BME280 and MPU6060 sensors 
I need to merge them together 

Kindly, I need help to Setup prj.conf file

Thanks & Regards

  • Hello, is there any news regarding this ticket please 
    thank u in advance 
    Kindly, 

  • commun25nov2021.zip

    Test the following sample. I added a work queue, such that you can offload the sensor reading when the button is pressed

    Get the sensor data from the functions get_mpu6050_data_work_fn and get_bme280_data_data_work_work_fn. (run the sensor_sample_fetch and sensor_channel_get functions inside work queue functions).

    Here is the changes I applied 
    diff --git a/samples/commun/src/main.c b/samples/commun/src/main.c
    index 44557eaaf..ff1bce410 100644
    --- a/samples/commun/src/main.c
    +++ b/samples/commun/src/main.c
    @@ -21,8 +21,15 @@ static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios,
     static struct gpio_callback button_cb_data;
     static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios,
     						     {0});
    -							 
    -							 
    +
    +#define APP_WORK_QUEUE_SIZE 4096	
    +#define APP_WORK_QUEUE_PRI -1
    +
    +K_THREAD_STACK_DEFINE(application_stack_area, APP_WORK_QUEUE_SIZE);				 
    +static struct k_work_q application_work_q;
    +
    +static struct k_work get_bme280_data_data_work;
    +static struct k_work get_mpu6050_data_work;		 
     
     static const char *now_str(void)
     {
    @@ -117,15 +124,39 @@ static void handle_mpu6050_drdy(const struct device *dev,
     	}
     }
     #endif /* CONFIG_MPU6050_TRIGGER */
    +
    +static void get_mpu6050_data_work_fn(struct k_work *work)
    +{
    +	printk("Get MPU6050 data\n");
    +}
    +
    +static void get_bme280_data_data_work_work_fn(struct k_work *work)
    +{
    +	printk("Get BME280 data\n");
    +}
    +
     void button_pressed(const struct device *dev, struct gpio_callback *cb,
     		    uint32_t pins)
     {
     	printk("Button pressed at %" PRIu32 "\n", k_cycle_get_32());
    +	k_work_submit_to_queue(&application_work_q, &get_bme280_data_data_work);
    +	k_work_submit_to_queue(&application_work_q, &get_mpu6050_data_work);
    +}
    +
    +static void work_init(void)
    +{
    +	k_work_init(&get_mpu6050_data_work, get_mpu6050_data_work_fn);
    +	k_work_init(&get_bme280_data_data_work, get_bme280_data_data_work_work_fn);
     }
     void main(void)
     {
     	int ret;
     
    +	k_work_queue_start(&application_work_q, application_stack_area,
    +			K_THREAD_STACK_SIZEOF(application_stack_area),
    +			APP_WORK_QUEUE_PRI, NULL);
    +	work_init();
    +
     	if (!device_is_ready(button.port)) {
     		printk("Error: button device %s is not ready\n",
     		       button.port->name);
    
    Best regards,
    Simon
  • Thank u Simon,
    you help was really appreciated 
    and i succeeded to display thanks to added the work queue 
    here's a capture from my final result



Related