Browse Source

fix size of the read buffer and substract one from the days

Helmut Pozimski 5 years ago
parent
commit
1481c8643f
1 changed files with 3 additions and 3 deletions
  1. 3 3
      rtc-ds13307.c

+ 3 - 3
rtc-ds13307.c

@@ -69,10 +69,10 @@ static int ds13307_read_time(struct device *dev, struct rtc_time *time) {
 	struct i2c_client *client;
 	int r;
 	int h12 = 0;
-	u8 buf[8], stopbit;
+	u8 buf[7], stopbit;
 	unsigned char addr = COMMON_SEC;
 	client = to_i2c_client(dev);
-	r = ds13307_read_bytes(client, &addr, buf, 8);
+	r = ds13307_read_bytes(client, &addr, buf, 7);
 	if (model_detected == DEVICE_DS1337) {
 		addr = DS1337_STAT;
 		r = ds13307_read_bytes(client, &addr, &stopbit, 1);
@@ -106,7 +106,7 @@ static int ds13307_read_time(struct device *dev, struct rtc_time *time) {
 	}
 	time->tm_mday = bcd2bin(buf[COMMON_DATE]);
 	time->tm_wday = bcd2bin(buf[COMMON_DAY]);
-	time->tm_mon = bcd2bin(buf[COMMON_MONTH]);
+	time->tm_mon = bcd2bin(buf[COMMON_MONTH]) - 1 ;
 	time->tm_year = bcd2bin(buf[COMMON_YEAR]) + 100;
 	return 0;
 }