Skip to contentSkip to conversation

iio: hx711: fix bug in reset functionality

PATCH In review Andreas Klinger 2 participants 2 messages Dec 13, 2017 – Dec 17, 2017

Subsystems (2)
lore
Share & tools
lore

Andreas Klinger

author maintainer
#0 lore raw

PATCH v4 2/2 iio: hx711: fix bug in reset functionality

Return value in hx711_reset() should indicate status of dout otherwise the calling function is reporting an error as false positive

If there are two reads too close to each other, then the second one will never succeed. This happens especially when using buffered mode with both channels enabled.

When changing the channel on every trigger event the former 100 ms are not enough for waiting until the device indicates normal mode.

Wait up to 1 second until the device turns into normal mode.

---
 drivers/iio/adc/hx711.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/iio/adc/hx711.c +6 -7
index a38162ee7dcb..9430b54121e0 100644
@@ -153,15 +153,16 @@ static int hx711_wait_for_ready(struct hx711_data *hx711_data)
 	int i, val;
 
 	/*
-	 * a maximum reset cycle time of 56 ms was measured.
-	 * we round it up to 100 ms
+	 * in some rare cases the reset takes quite a long time
+	 * especially when the channel is changed.
+	 * Allow up to one second for it
 	 */
 	for (i = 0; i < 100; i++) {
 		val = gpiod_get_value(hx711_data->gpiod_dout);
 		if (!val)
 			break;
-		/* sleep at least 1 ms */
-		msleep(1);
+		/* sleep at least 10 ms */
+		msleep(10);
 	}
 	if (val)
 		return -EIO;
@@ -203,9 +204,7 @@ static int hx711_reset(struct hx711_data *hx711_data)
 		 * after a dummy read we need to wait vor readiness
 		 * for not mixing gain pulses with the clock
 		 */
-		ret = hx711_wait_for_ready(hx711_data);
-		if (ret)
-			return ret;
+		val = hx711_wait_for_ready(hx711_data);
 	}
 
 	return val;
Signature · 4 lines
2.1.4


-- 
maintainer
#1 lore raw
Quoted 7 lines · On Wed, 13 Dec 2017 18:10:34 +0100 Andreas Klinger <[email protected]> wrote:

Return value in hx711_reset() should indicate status of dout otherwise the calling function is reporting an error as false positive

If there are two reads too close to each other, then the second one will never succeed. This happens especially when using buffered mode with both channels enabled.

Quoted 6 lines

When changing the channel on every trigger event the former 100 ms are not enough for waiting until the device indicates normal mode.

Wait up to 1 second until the device turns into normal mode.

An unrelated cleanup snuck in here, but as it's so trivial I'll let it go.

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.

Thanks,

Jonathan

Quoted 30 lines
---
 drivers/iio/adc/hx711.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/iio/adc/hx711.c +5 -4
index a38162ee7dcb..9430b54121e0 100644
@@ -153,15 +153,16 @@ static int hx711_wait_for_ready(struct hx711_data *hx711_data)
 	int i, val;
 
 	/*
-	 * a maximum reset cycle time of 56 ms was measured.
-	 * we round it up to 100 ms
+	 * in some rare cases the reset takes quite a long time
+	 * especially when the channel is changed.
+	 * Allow up to one second for it
 	 */
 	for (i = 0; i < 100; i++) {
 		val = gpiod_get_value(hx711_data->gpiod_dout);
 		if (!val)
 			break;
-		/* sleep at least 1 ms */
-		msleep(1);
+		/* sleep at least 10 ms */
+		msleep(10);
 	}
 	if (val)
 		return -EIO;

drivers/iio/adc/hx711.c static int hx711_reset(struct hx711_data *hx711_data) · line 207

Quoted 7 lines
drivers/iio/adc/hx711.c +1 -3
@@ -203,9 +204,7 @@ static int hx711_reset(struct hx711_data *hx711_data)
 		 * after a dummy read we need to wait vor readiness
 		 * for not mixing gain pulses with the clock
 		 */
-		ret = hx711_wait_for_ready(hx711_data);
-		if (ret)
-			return ret;
+		val = hx711_wait_for_ready(hx711_data);

This is technically an unrelated change and shouldn't be in this patch.

Quoted 3 lines
drivers/iio/adc/hx711.c +0 -0
 	}
 
 	return val;