v2n-temp-sensor
TMP112 temperature-sensor read loop on V2N's BRD_I2C. Reads the chip every second and prints the result in millicelsius.
Source: examples/v2n/v2n-temp-sensor/.
board.yaml
schema_version: 2
som:
sku: E1M-V2N101
carrier:
name: E1M-X-EVK
cores:
m33_sm:
os: zephyr
app: ./src
peripherals: [i2c]
chips:
- tmp112
diagnostics:
log_level: info
Source (abbreviated)
#include <alp/peripheral.h>
#include <alp/chips/tmp112.h>
#include <alp/e1m_pinout.h>
int main(void) {
alp_i2c_t *bus = alp_i2c_open(&(alp_i2c_config_t){
.bus_id = E1M_I2C0,
.bitrate_hz = 400000u,
});
if (bus == NULL) return -1;
tmp112_t sensor;
if (tmp112_init(&sensor, bus, 0x40) != ALP_OK) {
printk("[tmp112] init failed\n");
return -1;
}
for (int i = 0; i < 10; i++) {
int32_t mC;
if (tmp112_read_mC(&sensor, &mC) == ALP_OK) {
printk("[tmp112] %d.%03d C\n", mC / 1000, abs(mC % 1000));
}
k_msleep(1000);
}
alp_i2c_close(bus);
return 0;
}
See also
Questions about this page? Discuss in Community Forum