0

I'm using an ESP32 which I connected to a MAX31329 RTC through I2C.

Unfortunately I can't read any register from the RTC. After modifying the MAX31328 library didn't work, I tried reading single registers directly. Here is the code:

#include "Wire.h"

int seconds = 0;
int ret = 0;

void setup() {
  
Serial.begin(115200);
delay(500);

Wire.begin(33,32,100000);

delay(500);
Wire.beginTransmission(0x68);
  Wire.write(0x06);
  Wire.write(13);
  ret = Wire.endTransmission();
  if(ret != 0)
    Serial.println("i2c Setup failed");
    
  delay(500);
}

void loop() {
  
  Wire.beginTransmission(0x68);
  Wire.write(0x06);
  
  Wire.requestFrom(0x68,1);
  seconds = Wire.read();
  ret = Wire.endTransmission();
  if(ret != 0)
    Serial.println("Read failed");
 
  Serial.println(seconds);
  
delay(1000);
}

The register always returns 0.

Do you see the error in my code? The datasheet of the MAX31329 can be found here.

I'm trying for days now and have no clue what the problem is. Thanks a lot for your support in advance.

Best regards,

Martin

0

3 Answers 3

1

You are doing things in the wrong order.

 Wire.beginTransmission(0x68);
 Wire.write(0x06);
 Wire.requestFrom(0x68,1);
 seconds = Wire.read();
 ret = Wire.endTransmission();

The request is sent on the endTransmission call, so you need to do that before trying to get a response. In other words:

  Wire.beginTransmission(0x68);
  Wire.write(0x06);
  ret = Wire.endTransmission();

  Wire.requestFrom(0x68,1);
  seconds = Wire.read();
1

To read the max31329 you do need to do the following as Nick Said

Wire.beginTransmission(0x68);
Wire.write(0x06);
ret = Wire.endTransmission(false); //No Stop, so the request is a restart

Wire.requestFrom(0x68,1);
seconds = Wire.read();

But it needs to be a repeated restart following the write to register 0x06, hence the false in Wire.endTransmission(false). It took me ages to figure out as the DS3231 and MAX31328 don't required this, I actually found this writen in the data sheet for the MAX31343 which has a similar set of registers with seconds starting at 0x06 unlike the previous clocks that start at 0x00. Interestingly with these ones, reading the status register 0x00 will return to you any flags for interupts and automatically reset them after reading the register, which I think is new and better.

0

I have been using the ESP32 for about 10 years now and it can be finicky

I2C is an Open Collector interface requiring Pull-up resistors to work.

If you are using a board module it likely has the pull-ups if not make sure you have them (around 1.5K OHMS) from SDA and SCL to 3.3 Vcc.

I suggest starting with Arduino's i2cdetect.ino and debug if it is being seen.
If not you have a wiring issue.

while both other answers are fairly good, you show no schematic or mention if you are using a RTC board.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.