From 8ce7ff28362a350672d695dada167c7246fc2b22 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Mon, 23 Oct 2017 14:41:04 +0200 Subject: [PATCH 1/2] ds1307: return error when nothing is read or written on initialization It hints at to an unconnected devices ;-) --- drivers/ds1307/ds1307.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/ds1307/ds1307.c b/drivers/ds1307/ds1307.c index c982adbd1e..3141d8ae14 100644 --- a/drivers/ds1307/ds1307.c +++ b/drivers/ds1307/ds1307.c @@ -64,7 +64,7 @@ int ds1307_init(ds1307_t *dev, const ds1307_params_t *params) } /* normalize hour format */ res = i2c_read_reg(dev->i2c, DS1307_I2C_ADDRESS, DS1307_REG_HOUR, &hour); - if (res < 0) { + if (res <= 0) { /* should be 1 if device is connected */ i2c_release(dev->i2c); DEBUG("ds1307: Error reading HOUR register on init: %i\n", res); return -1; @@ -73,7 +73,7 @@ int ds1307_init(ds1307_t *dev, const ds1307_params_t *params) _convert_12_to_24(hour)); i2c_release(dev->i2c); - if (res < 0) { + if (res <= 0) { DEBUG("ds1307: Error writing HOUR register on init: %i\n", res); return -1; } From 500aa285f30359dfc84e4ba30047cb41fae0a219 Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Mon, 23 Oct 2017 14:42:27 +0200 Subject: [PATCH 2/2] tests: ds1307: adapt test result for initialization error --- tests/driver_ds1307/tests/01-run.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/driver_ds1307/tests/01-run.py b/tests/driver_ds1307/tests/01-run.py index 6ae6e86ed5..ab9bdb938f 100755 --- a/tests/driver_ds1307/tests/01-run.py +++ b/tests/driver_ds1307/tests/01-run.py @@ -13,7 +13,8 @@ sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner')) import testrunner def testfunc(child): - child.expect(u"OK \\([0-9]+ tests\\)") + child.expect([r"OK \([0-9]+ tests\)", + r"error: unable to initialize RTC \[I2C initialization error\]"]) if __name__ == "__main__": sys.exit(testrunner.run(testfunc))