Programming nrf52832 d internal temperature sensor

Hi,

I am trying to program the internal temperature of the nrf52832 development kit, I have this code so far it builds and when I flash it on the board; I get a message that the temp driver cannot be found. Can someone please help me with this issue?


#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/sensor.h>
#include <zephyr/drivers/i2c.h> /* STEP 3 - Include the header file of the I2C API */
#include <zephyr/sys/printk.h> /* STEP 4.1 - Include the header file of printk() */

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

void main(void)
{
struct device *temp_dev;

int ret;
temp_dev = device_get_binding("TEMP_0");
if (!temp_dev) {
printk("Didn't find the temp driver!\n");
return;
}

while (1) {
struct sensor_value val;

ret = sensor_sample_fetch(temp_dev);

if (ret) {
printk("Failed to sample temp sensor!\n");
return;
}

ret = sensor_channel_get(temp_dev, SENSOR_CHAN_DIE_TEMP, &val);

if (ret) {
printk("failed to get temp sensor data!\n");
return;
}
printk("Temp %d.%d\n", val.val1, val.val2);

k_msleep(SLEEP_TIME_MS);
  }
}

Thanks in advance

Related