Skip to content

Commit 9ed6005

Browse files
committed
don't reset the sensor in the begin() func
1 parent 358feb3 commit 9ed6005

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ See [sdpsensor-esp-arduino.ino](./sdpsensor-esp-arduino.ino).
1212
Serial output:
1313

1414
```
15-
[ 1021][I][sdpsensor.cpp:86] initI2C(): I2C0 line initialized
16-
[ 1021][I][sdpsensor.cpp:204] reset(): SDPSensor::reset ESP_OK
17-
[ 1042][I][sdpsensor.cpp:157] begin(): Initialized SDP31 500Pa sensor (PID=0x03010188)
18-
[ 1133][I][sdpsensor.cpp:169] begin(): SDP31 pressure scale: 60
19-
[ 1133][I][sdpsensor.cpp:182] startContinuous(): SDPSensor::startContinuous ESP_OK
15+
[ 1021][I][sdpsensor.cpp:95] initI2C(): I2C0 line initialized
16+
[ 1021][I][sdpsensor.cpp:232] stopContinuous(): SDPSensor::stopContinuous ESP_OK
17+
[ 1043][I][sdpsensor.cpp:182] begin(): Initialized SDP31 500Pa sensor (PID=0x03010188)
18+
[ 1134][I][sdpsensor.cpp:200] begin(): SDP31 pressure scale: 60
19+
[ 1134][I][sdpsensor.cpp:219] startContinuous(): SDPSensor::startContinuous ESP_OK
2020
2121
[ 2154][I][sdpsensor-esp-arduino.ino:32] loop(): raw pressure: 0, err code: ESP_OK
2222
...
2323
```
2424

25+
### Resetting the sensor
26+
27+
If the sensor was working in a continuous mode, prior to executing any I2C commands, it ought to be reset by calling either the `stopContinuous()` or `reset()` function. Note, however, that the `reset` commands are received by *all* I2C peripherals connected to the same I2C line (port), because it employs the `0x00` address, which is the I2C general call address.
28+

sdpsensor-esp-arduino.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ void setup() {
2020
Serial.begin(115200);
2121
delay(1000); // let serial console settle
2222
sdp.initI2C(19, 23); // same as Wire.begin(19, 23)
23+
sdp.stopContinuous(); // sdp.reset() is also possible
2324
sdp.begin();
2425
sdp.startContinuous();
2526
}

sdpsensor.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ void logInitFailed(esp_err_t err) {
106106

107107

108108
esp_err_t SDPSensor::begin() {
109-
SDPSensor::reset(); // stop continuous mode
110-
111109
// commands to read product id
112110
uint8_t cmd0[SDPSENSOR_I2C_CMD_LEN] = { 0x36, 0x7C };
113111
uint8_t cmd1[SDPSENSOR_I2C_CMD_LEN] = { 0xE1, 0x02 };
@@ -213,8 +211,6 @@ uint16_t SDPSensor::getPressureScale() {
213211

214212

215213
esp_err_t SDPSensor::startContinuous() {
216-
if (!initialized) return ESP_ERR_INVALID_STATE;
217-
218214
uint8_t cmd[SDPSENSOR_I2C_CMD_LEN] = { 0x36, 0x1E };
219215
const TickType_t ticks_to_wait_long = pdMS_TO_TICKS(100);
220216
esp_err_t err = i2c_master_write_to_device(i2c_port, i2c_addr, cmd,
@@ -228,8 +224,6 @@ esp_err_t SDPSensor::startContinuous() {
228224

229225

230226
esp_err_t SDPSensor::stopContinuous() {
231-
if (!initialized) return ESP_ERR_INVALID_STATE;
232-
233227
uint8_t cmd[SDPSENSOR_I2C_CMD_LEN] = { 0x3F, 0xF9 };
234228
const TickType_t ticks_to_wait_long = pdMS_TO_TICKS(100);
235229
esp_err_t err = i2c_master_write_to_device(i2c_port, i2c_addr, cmd,

sdpsensor.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ class SDPSensor {
4646
/**
4747
* Initialize an SDP sensor.
4848
*
49-
* Firstly, it resets the sensor prior to executing any I2C commands.
50-
* Then it reads and saves the sensor serial number and diff pressure scale.
51-
* The returned error code other than ESP_OK (0) means that the sensor has
52-
* not been properly initialized.
49+
* You may need to call `stopContinuous()` or `reset()` function
50+
* prior to initializing the sensor, if previously it was working in
51+
* a continuous mode.
52+
* The product ID and the diff pressure scale are read and saved here.
53+
* The returned error code other than ESP_OK (0) means that the sensor
54+
* has not been properly initialized.
5355
*
5456
* @returns the error code (defined in esp_err.h)
5557
*/

0 commit comments

Comments
 (0)