samples: tmp116: Add access to eeprom
Add read access to internal tmp116 eeprom which contains the device unique id after manufacturing Signed-off-by: Guillaume Lager <g.lager@innoseis.com>
This commit is contained in:
parent
972e5d0274
commit
ed68ef5678
|
@ -10,6 +10,15 @@
|
|||
compatible = "ti,tmp116";
|
||||
reg = <0x4B>;
|
||||
label = "TMP116";
|
||||
#address-cells = <1>;
|
||||
#size-cells = <0>;
|
||||
|
||||
eeprom: ti_tmp116_eeprom@0 {
|
||||
compatible = "ti,tmp116-eeprom";
|
||||
reg = <0x0>;
|
||||
label = "TMP116_EEPROM";
|
||||
read-only;
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
CONFIG_STDOUT_CONSOLE=y
|
||||
CONFIG_I2C=y
|
||||
CONFIG_SENSOR=y
|
||||
CONFIG_SENSOR_INIT_PRIORITY=90
|
||||
CONFIG_TMP116=y
|
||||
CONFIG_EEPROM=y
|
||||
CONFIG_EEPROM_INIT_PRIORITY=91
|
||||
CONFIG_EEPROM_TMP116=y
|
||||
|
|
|
@ -7,12 +7,17 @@
|
|||
#include <zephyr.h>
|
||||
#include <device.h>
|
||||
#include <drivers/sensor.h>
|
||||
#include <drivers/eeprom.h>
|
||||
#include <drivers/sensor/tmp116.h>
|
||||
#include <sys/printk.h>
|
||||
#include <sys/__assert.h>
|
||||
|
||||
static uint8_t eeprom_content[EEPROM_TMP116_SIZE];
|
||||
|
||||
void main(void)
|
||||
{
|
||||
const struct device *dev;
|
||||
const struct device *dev = DEVICE_DT_GET(DT_INST(0, ti_tmp116));
|
||||
const struct device *eeprom = DEVICE_DT_GET(DT_INST(0, ti_tmp116_eeprom));
|
||||
struct sensor_value temp_value;
|
||||
|
||||
/* offset to be added to the temperature
|
||||
|
@ -21,11 +26,22 @@ void main(void)
|
|||
struct sensor_value offset_value;
|
||||
int ret;
|
||||
|
||||
dev = device_get_binding(DT_LABEL(DT_INST(0, ti_tmp116)));
|
||||
__ASSERT(dev != NULL, "Failed to get TMP116 device binding");
|
||||
__ASSERT(device_is_ready(dev), "TMP116 device not ready");
|
||||
__ASSERT(device_is_ready(eeprom), "TMP116 eeprom device not ready");
|
||||
|
||||
printk("Device %s - %p is ready\n", dev->name, dev);
|
||||
|
||||
ret = eeprom_read(eeprom, 0, eeprom_content, sizeof(eeprom_content));
|
||||
if (ret == 0) {
|
||||
printk("eeprom content %02x%02x%02x%02x%02x%02x%02x%02x\n",
|
||||
eeprom_content[0], eeprom_content[1],
|
||||
eeprom_content[2], eeprom_content[3],
|
||||
eeprom_content[4], eeprom_content[5],
|
||||
eeprom_content[6], eeprom_content[7]);
|
||||
} else {
|
||||
printk("Failed to get eeprom content\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* if an offset of 2.5 oC is to be added,
|
||||
* set val1 = 2 and val2 = 500000.
|
||||
|
|
Loading…
Reference in a new issue