Skip to content

Commit a7c0ec2

Browse files
ydamigoskartben
authored andcommitted
drivers: sensor: hs400x: Soft reset HS400x during initialization
Soft reset HS400x during initialization to make sure that device is at a known state and writeable registers have the default values. Signed-off-by: Ioannis Damigos <ioannis.damigos.uj@renesas.com>
1 parent b86d8c0 commit a7c0ec2

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

drivers/sensor/renesas/hs400x/hs400x.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,45 @@ static int hs400x_channel_get(const struct device *dev, enum sensor_channel chan
137137
return 0;
138138
}
139139

140+
static void hs400x_all_measurements_stop(const struct device *dev)
141+
{
142+
const struct hs400x_config *cfg = dev->config;
143+
const uint8_t periodic_measurement_stop = 0x30;
144+
uint8_t dummy[2];
145+
146+
/*
147+
* Stop previous periodic measurement.
148+
* If a periodic measurement is not running, HS400x device replies with NACK.
149+
*/
150+
i2c_write_dt(&cfg->bus, &periodic_measurement_stop, 1);
151+
152+
/*
153+
* Clear previous no-hold measurement.
154+
* If a measurement is not complete, HS400x device replies with NACK.
155+
*/
156+
i2c_read_dt(&cfg->bus, dummy, 2);
157+
}
158+
140159
static int hs400x_init(const struct device *dev)
141160
{
142161
const struct hs400x_config *cfg = dev->config;
162+
const uint8_t reset_command = 0xFE;
163+
int rc;
143164

144165
if (!i2c_is_ready_dt(&cfg->bus)) {
145166
LOG_ERR("I2C dev %s not ready", cfg->bus.bus->name);
146167
return -ENODEV;
147168
}
148169

170+
hs400x_all_measurements_stop(dev);
171+
172+
rc = i2c_write_dt(&cfg->bus, &reset_command, 1);
173+
if (rc < 0) {
174+
LOG_ERR("Failed to send reset command.");
175+
return rc;
176+
}
177+
k_msleep(500);
178+
149179
return 0;
150180
}
151181

0 commit comments

Comments
 (0)