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

asked May 7, 2022 at 20:46
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();
answered May 8, 2022 at 7:09
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.

answered Jan 11, 2023 at 14:58
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.

answered Jan 12, 2023 at 5:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.