From ba982e17c7f0d93874b89f08d7897bdca9da8500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Thu, 9 Feb 2017 10:55:38 +0100 Subject: [PATCH] check return code --- lib/rtc_ds1307.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/rtc_ds1307.c b/lib/rtc_ds1307.c index 3ca51f8..5cced6a 100644 --- a/lib/rtc_ds1307.c +++ b/lib/rtc_ds1307.c @@ -146,7 +146,9 @@ uint8_t* rtc_ds1307_read_time(void) static uint8_t time[7] = {0}; // store time {seconds, minutes, hours, day, date, month, year} uint8_t data[7] = {0}; // to read data over I2C const uint8_t address[] = {0x00}; // memory address for data - i2c_read(RTC_DS1307_I2C_ADDR, address, LENGTH(address), data, LENGTH(data)); // read all time bytes + if (!i2c_read(RTC_DS1307_I2C_ADDR, address, LENGTH(address), data, LENGTH(data))) { // read all time bytes + return NULL; + } time[0] = ((data[0]&0x70)>>4)*10+(data[0]&0x0f); // convert seconds from BCD time[1] = (data[1]>>4)*10+(data[1]&0x0f); // convert minutes from BCD time[2] = 0; // re-initialize hours