<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Need to add driver Max30001 to nrf52dk</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/118763/need-to-add-driver-max30001-to-nrf52dk</link><description>Hello team, 
 We are using nrf52dk with nrf52832 by vs code nrf connect sdk extension. 
 I have add zephyr led blinky application and flash it on the board and it&amp;#39;s working fine. 
 
 Now I need to add the driver code of Max30001 git hub link 
 https:</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 04 Mar 2025 18:16:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/118763/need-to-add-driver-max30001-to-nrf52dk" /><item><title>RE: Need to add driver Max30001 to nrf52dk</title><link>https://devzone.nordicsemi.com/thread/525809?ContentTypeID=1</link><pubDate>Tue, 04 Mar 2025 18:16:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39e039f9-2f65-4cff-aa78-c69e7cacd1ff</guid><dc:creator>Sagar Patel</dc:creator><description>&lt;p&gt;Sorry for late reply,&amp;nbsp;&lt;br /&gt;Thanks for the help. This gave me better idea and i have successfully integrate the driver.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Need to add driver Max30001 to nrf52dk</title><link>https://devzone.nordicsemi.com/thread/522233?ContentTypeID=1</link><pubDate>Mon, 10 Feb 2025 14:27:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ba69f30c-c9b2-4010-b7f2-22f3a56ba866</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I have not tested this sensor, but I got it building, so perhaps you can test it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Following the guide you linked to, I added the west.yml snippet to the west.yml file found in NCS\nrf\west.yml, then I opened a cmd terminal, and called &amp;quot;west update&amp;quot;, so that it will download the MAX30001 driver to the correct location. NB: You only add from the line starting with &amp;quot;- name: MAX30001&amp;quot;, so it looks something like this:&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1739185800174v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Then, in whatever application project you are using, add the following to your prj.conf (NB: There is a typo in the guide. It should be &amp;quot;CONFIG_SENSOR_MAX30001=y&amp;quot;, not &amp;quot;CONFIG_MAX30001=y&amp;quot;.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_GPIO=y
CONFIG_SENSOR=y
CONFIG_SENSOR_MAX30001=y
CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58=y

# Log module
CONFIG_LOG=y
CONFIG_LOG_BACKEND_UART=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then, if your application folder doesn&amp;#39;t have a file called &amp;quot;nrf52dk_nrf52832.overlay&amp;quot;, then create it, and in there, write:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;spi2 {
	compatible = &amp;quot;nordic,nrf-spim&amp;quot;;
	status = &amp;quot;okay&amp;quot;;

	pinctrl-0 = &amp;lt;&amp;amp;spi2_default&amp;gt;;
	pinctrl-1 = &amp;lt;&amp;amp;spi2_sleep&amp;gt;;
	pinctrl-names = &amp;quot;default&amp;quot;, &amp;quot;sleep&amp;quot;;
	cs-gpios = &amp;lt;&amp;amp;gpio0 22 GPIO_ACTIVE_LOW&amp;gt;;

    max30001: max30001@0 {
		compatible = &amp;quot;maxim,max30001&amp;quot;;
		status = &amp;quot;okay&amp;quot;;
		reg = &amp;lt;0x0&amp;gt;;
		spi-max-frequency = &amp;lt;DT_FREQ_M(1)&amp;gt;;
		intb-gpios = &amp;lt;&amp;amp;gpio0 12 GPIO_ACTIVE_LOW&amp;gt;;
		rtor-enabled;
		ecg-enabled;
		bioz-enabled;
		ecg-gain = &amp;lt;3&amp;gt;;
		ecg-invert;
	};
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And do a pristine build (only needed this time, for the compiler to detect the new nrf52dk_nrf52832.overlay file):&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/pastedimage1739186189797v3.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Note that you will get a build error mentioning&amp;nbsp;CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58, so add:&lt;/p&gt;
&lt;p&gt;CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58=y&lt;/p&gt;
&lt;p&gt;to your prj.conf, and build again.&lt;/p&gt;
&lt;p&gt;If you want to change the default pins used for spi2, just add this on top of your nrf52dk_nrf52832.overlay file:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;pinctrl {
	spi2_default: spi2_default {
		group1 {
			psels = &amp;lt;NRF_PSEL(SPIM_SCK, 0, 25)&amp;gt;,
				&amp;lt;NRF_PSEL(SPIM_MOSI, 0, 23)&amp;gt;,
				&amp;lt;NRF_PSEL(SPIM_MISO, 0, 24)&amp;gt;;
		};
	};

	spi2_sleep: spi2_sleep {
		group1 {
			psels = &amp;lt;NRF_PSEL(SPIM_SCK, 0, 25)&amp;gt;,
				&amp;lt;NRF_PSEL(SPIM_MOSI, 0, 23)&amp;gt;,
				&amp;lt;NRF_PSEL(SPIM_MISO, 0, 24)&amp;gt;;
			low-power-enable;
		};
	};

};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and change the pin numbers to the ones that you want to use. If it is a shield, you may need to look up which ones that are used on the shield. Note that I changed the spi3 to spi2 in the overlay, because the nRF52832 only has spi0, spi1 and spi2.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As for the actual application, this is what is a bit difficult for me to test. In your main.c, you need to include these two:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;zephyr/devicetree.h&amp;gt;
#include &amp;lt;zephyr/drivers/sensor.h&amp;gt;
#include &amp;quot;max30001.h&amp;quot;
#include &amp;lt;zephyr/logging/log.h&amp;gt;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Then something like this&amp;nbsp;&lt;strong&gt;may&lt;/strong&gt; work (but I am unable to test it):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Copyright (c) 2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/drivers/gpio.h&amp;gt;
#include &amp;lt;zephyr/devicetree.h&amp;gt;
#include &amp;lt;zephyr/drivers/sensor.h&amp;gt;
#include &amp;quot;max30001.h&amp;quot;
#include &amp;lt;zephyr/logging/log.h&amp;gt;

#define LOG_MODULE_NAME app
LOG_MODULE_REGISTER(LOG_MODULE_NAME);

/* 1000 msec = 1 sec */
#define SLEEP_TIME_MS   2000

/* The devicetree node identifier for the &amp;quot;led0&amp;quot; alias. */
#define LED0_NODE DT_ALIAS(led0)

/*
 * A build error on this line means your board is unsupported.
 * See the sample documentation for information on how to fix this.
 */
static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(LED0_NODE, gpios);

#define SENSOR_DEVICE_NAME max30001

#define THREAD_STACKSIZE        1024
#define THREAD_PRIORITY         7

K_THREAD_STACK_DEFINE(sensor_thread_stack, THREAD_STACKSIZE);
static struct k_thread sensor_thread;
K_MUTEX_DEFINE(sensor_mutex);
static int32_t sensor_value;

static void thread_entry(void *p1, void *p2, void *p3)
{
	int ret;
	struct sensor_value my_sensor_value;

	const struct device *dev = (const struct device *)p1;
	struct k_mutex *temp_mutex = (struct k_mutex *)p2;
	int32_t *temp = (int32_t *)p3;

	while (1) {
        LOG_INF(&amp;quot;starting...&amp;quot;);
		ret = sensor_sample_fetch(dev);
		if (ret != 0) {
			LOG_INF(&amp;quot;sensor_sample_fetch failed ret %d\n&amp;quot;, ret);
			return;
		}

		ret = sensor_channel_get(dev, SENSOR_CHAN_ECG_UV, &amp;amp;my_sensor_value);    // Look up what this channel does in &amp;quot;max30001.c&amp;quot;
		if (ret != 0) {
			LOG_INF(&amp;quot;sensor_channel_get failed ret %d\n&amp;quot;, ret);
			return;
		}
		if (k_mutex_lock(temp_mutex, K_MSEC(2000)) == 0) {
			*temp = my_sensor_value.val1;
			k_mutex_unlock(temp_mutex);
		} else {
			LOG_INF(&amp;quot;Unable to lock mutex\n&amp;quot;);
		}
        LOG_INF(&amp;quot;sleeping...&amp;quot;);
		k_sleep(K_MSEC(2000));
	}
}

void sensor_init(void)
{
    const struct device *dev = DEVICE_DT_GET_ANY(SENSOR_DEVICE_NAME);
    
    __ASSERT(dev != NULL, &amp;quot;Failed to get device binding&amp;quot;);
	__ASSERT(device_is_ready(dev), &amp;quot;Device %s is not ready&amp;quot;, dev-&amp;gt;name);
	printk(&amp;quot;device is %p, name is %s\n&amp;quot;, dev, dev-&amp;gt;name);
	
    k_thread_create(&amp;amp;sensor_thread, sensor_thread_stack,
			K_THREAD_STACK_SIZEOF(sensor_thread_stack),
			thread_entry, (void *)dev, (void *)&amp;amp;sensor_mutex, (void*)&amp;amp;sensor_value,
			THREAD_PRIORITY, 0, K_FOREVER);
	k_thread_start(&amp;amp;sensor_thread);
}

int32_t value_get(void)
{
	int32_t val = 0;

	if (k_mutex_lock(&amp;amp;sensor_mutex, K_MSEC(100)) == 0) {
		val = sensor_value;
		k_mutex_unlock(&amp;amp;sensor_mutex);
	}

	return val;
}

int main(void)
{
	int ret;
	bool led_state = true;
    int32_t sensor_value;
    sensor_init();

	if (!gpio_is_ready_dt(&amp;amp;led)) {
		return 0;
	}

	ret = gpio_pin_configure_dt(&amp;amp;led, GPIO_OUTPUT_ACTIVE);
	if (ret &amp;lt; 0) {
		return 0;
	}

	while (1) {
        sensor_value = value_get();
        LOG_INF(&amp;quot;value = %d&amp;quot;, sensor_value);

		ret = gpio_pin_toggle_dt(&amp;amp;led);
		if (ret &amp;lt; 0) {
			return 0;
		}

		led_state = !led_state;
		LOG_INF(&amp;quot;LED state: %s\n&amp;quot;, led_state ? &amp;quot;ON&amp;quot; : &amp;quot;OFF&amp;quot;);
		k_msleep(SLEEP_TIME_MS);
	}
	return 0;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Attaching the whole application, in case I missed something along the way. As you can see throughout, I added logging using the log module as well.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>