This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How can we connect the max30101 from the \ncs\zephyr\samples\sensor\max30101 .. i added the links to a blinky and it compiles successfully but can't seem to get the i2c working .. please help

Main in green

/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr.h>
#include <device.h>
#include <gpio.h>
#include <misc/printk.h>
#include <stdio.h>
#include <string.h>
#include <sensor.h>

#define LED_PORT LED0_GPIO_CONTROLLER
#define LED LED1_GPIO_PIN

/* 1000 msec = 1 sec */
#define SLEEP_TIME 1000

void main(void)
{


printk("UART loopback start!\n");

int cnt = 0;
//struct device *dev;

//dev = device_get_binding(LED_PORT);
/* Set LED pin as output */
//gpio_pin_configure(dev, LED, GPIO_DIR_OUT);


struct sensor_value green;
struct device *dev = device_get_binding("MAX30101");

if (dev == NULL) {
printk("Could not get max30101 device\n");
return;
}

while (1) {
/* Set pin to HIGH/LOW every 1 second */
sensor_sample_fetch(dev);
sensor_channel_get(dev, SENSOR_CHAN_GREEN, &green);
/* Print green LED data*/
printk("GREEN=%d\n", green.val1);
k_sleep(20);
//gpio_pin_write(dev, LED, cnt % 2);
printk("Hello World! %s\n", CONFIG_BOARD);
cnt++;
k_sleep(SLEEP_TIME);
}
}

CONF FILE in red

CONFIG_GPIO=y
CONFIG_SERIAL=y
CONFIG_I2C=y
CONFIG_I2C_NRFX=y
CONFIG_I2C_1=y
CONFIG_I2C_1_NRF_TWIM=y
CONFIG_SENSOR=y
CONFIG_LOG=y
CONFIG_TRUSTED_EXECUTION_NONSECURE=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_AT_HOST_LIBRARY=y
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_SENSOR_LOG_LEVEL_DBG=y
CONFIG_MAX30101=y

Parents Reply Children
  • &i2c1 {
    status = "ok";
    sda-pin = <10>;
    scl-pin = <11>;
    clock-frequency = <100000>; 
    };
    
    &i2c1 {
      max30101@57 {
        compatible = "max,max30101";
        reg = <0x57>;
        label = "MAX30101";
        irq-gpios = <&gpio0 20 0>;
      };
    };

    Is this topology correct?

    Can you share a guide for the overlay files regarding i2c 

    Thanks

  • Not sure if there is a guide for that. I've figured it out while looking at the files under zephyr folder;

    "zephyr/dts/bindings" folder has the template files that will give you an idea about what parameters you can put in overlay file

    i think in your case it should be like

    &i2c1 {
    status = "ok";
    sda-pin = <10>;
    scl-pin = <11>;
    clock-frequency = <100000>; 
      max30101@57 {
        compatible = "max,max30101";
        reg = <0x57>;
        label = "MAX30101";
        irq-gpios = <&gpio0 20 0>;
      };
    };

  • Thank you 

    I'm getting this error while compilation when it reaches nrfx.twim.c

    'NRF_TWIM1' undeclared (first use in this function); did you mean 'NRF_TWIM2'?

    Thats the prj.conf 

    CONFIG_GPIO=y
    CONFIG_SERIAL=y
    CONFIG_I2C=y
    CONFIG_I2C_NRFX=y
    CONFIG_I2C_1=y
    CONFIG_I2C_1_NRF_TWIM=y
    CONFIG_SENSOR=y
    CONFIG_LOG=y
    CONFIG_TRUSTED_EXECUTION_NONSECURE=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_AT_HOST_LIBRARY=y
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_SENSOR_LOG_LEVEL_DBG=y
    CONFIG_MAX30101=y
    
    

    And the main

    /*
     * Copyright (c) 2016 Intel Corporation
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <zephyr.h>
    #include <device.h>
    #include <gpio.h>
    #include <misc/printk.h>
    #include <stdio.h>
    #include <string.h>
    #include <sensor.h>
    
    
    
    #define LED_PORT LED0_GPIO_CONTROLLER
    #define LED	LED1_GPIO_PIN
    
    /* 1000 msec = 1 sec */
    #define SLEEP_TIME 	1000
    
    
    
    
    
    void main(void)
    {
    
           
    	printk("UART loopback start!\n");
    
    	int cnt = 0;
    	//struct device *dev;
    
    	//dev = device_get_binding(LED_PORT);
    	/* Set LED pin as output */
    	//gpio_pin_configure(dev, LED, GPIO_DIR_OUT);
    
    
            struct sensor_value green;
            struct device *dev = device_get_binding("MAX30101");
    
    	if (dev == NULL) {
    		printk("Could not get max30101 device\n");
    		return;
    	}
    
    	while (1) {
    		/* Set pin to HIGH/LOW every 1 second */
                    sensor_sample_fetch(dev);
    		sensor_channel_get(dev, SENSOR_CHAN_GREEN, &green);
    		/* Print green LED data*/
    		printk("GREEN=%d\n", green.val1);
    		k_sleep(20);
    		//gpio_pin_write(dev, LED, cnt % 2);
                    printk("Hello World! %s\n", CONFIG_BOARD);
    		cnt++;
    		k_sleep(SLEEP_TIME);
    	}
    }
    
     

  • Try to do the following:

    • Copy the folder max30101 (<..>ncs\zephyr\samples\sensor\) into your working folder (e.g. <..>ncs\nrf\samples\nrf9160)
    • Don't modify any of the files, let the prj.conf and main.c be as it is
    • Create a file named nrf9160_pca10090ns.overlay inside the max30101 folder, and add the following inside it:

    &i2c2 {	
    	max30101@57 {
    		compatible = "max,max30101";
    		reg = <0x57>;
    		label = "MAX30101";
    	};
    };

    This extends on the enabled i2c2 device tree node from <..>\ncs\zephyr\boards\arm\nrf9160_pca10090\nrf9160_pca10090_common.dts

    • Build the example with the board set as nrf9160_pca10090ns (or whatever you chose for the overlay file)
    • Connect the max30101 using the SDA and SCL pins as defined in the i2c2 device tree node from <..>\ncs\zephyr\boards\arm\nrf9160_pca10090\nrf9160_pca10090_common.dts (If you haven overwritten it in the overlay file).

    Best regards,

    Simon

Related