Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:31 25 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Problems with RTC DS3231 on RP2040 ZERO

Author Message
v.lenzer
Regular Member

Joined: 04/05/2024
Location: Germany
Posts: 49
Posted: 01:56pm 06 May 2024
Copy link to clipboard 
Print this post

Hello everyone! I am new to this forum. The friendly interactions here prompted me to register. I am now almost 70 years old and have been working with microcontrollers for decades. I recently discovered the RP2040 Zero, which I program with MMBasic. I can now control various LCD, TFT, SD cards and output sound. I also get along well with SPI and I2C.
I have problems with the RTC DS3231. I set the time by entering it on the console with RTC SETTIME YYYY,MM,...and so on. This also works without errors. The option for I2C is entered, I have defined the I2C pins (GP0 and GP1).
In the program I query the time with RTC GETTIME. That works too. The only error is that the time I get here is the time at which I switched off the voltage on the RP2040 Zero. The RTC is obviously stopped and the battery in the RTC circuit ensures that the time is remembered.
Has anyone already read the time with the RP2040 Zero?
I had the text translated using Google Translator. I hope this doesn't cause any misunderstandings.

rtc gettime
CLS 0

do

font 2: Text 0,12, Date$
Font 3: Text 0,40, time$

loop

Best wishes! Joachim
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3800
Posted: 03:16pm 06 May 2024
Copy link to clipboard 
Print this post

Welcome!

Sorry I don't know the answer - but your post is clear and someone probably will know.

John
 
JanVolk
Senior Member

Joined: 28/01/2023
Location: Netherlands
Posts: 144
Posted: 05:02pm 06 May 2024
Copy link to clipboard 
Print this post

Welcome v.lenzer,

Which version of MMBasic are you using?
How is your option list?
I currently don't have an RP2040-zero with an LCD screen.
Perhaps the line OPTION RTC AUTO ENABLE is missing from your options list?
Tested on RP2040-GEEK with SDA=4 AND SCL=5 and your program works well for me.

Jan
 
v.lenzer
Regular Member

Joined: 04/05/2024
Location: Germany
Posts: 49
Posted: 05:07pm 06 May 2024
Copy link to clipboard 
Print this post

Hello Jan!
No, I do not have the option RTC AUTO ENABLE. I guess, that's the solution. I gonna try it this evening. Thank's a lot!
Best wishes! Joachim
 
JanVolk
Senior Member

Joined: 28/01/2023
Location: Netherlands
Posts: 144
Posted: 06:29pm 06 May 2024
Copy link to clipboard 
Print this post

v.lenzer,

Try this.

RTC GETTIME
CLS 0

Do
 Font 2: Text   0, 0, Left$((Day$(NOW)), 3)
 Font 2: Text  50, 0, Date$
 Font 2: Text 180, 0, Left$(Time$, 5)
Loop

Jan
 
v.lenzer
Regular Member

Joined: 04/05/2024
Location: Germany
Posts: 49
Posted: 08:26pm 06 May 2024
Copy link to clipboard 
Print this post

Unfortunately, entering OPTION RTC AUTO ENABLE did not resolve the error. Not even the suggestion
Font 2: Text 0, 0, Left$((Day$(NOW)), 3)
Font 2: Text 50, 0, Date$
Font 2: Text 180, 0, Left$(Time$, 5)

I work with MMBasic version 5.08
The options are:

OPTION SYSTEM SPI GP6,GP3,GP4
OPTION SYSTEM I2C GP0,GP1
AUTORUN ON OPTION
OPTION LCD PANEL ILI9341, LANDSCAPE,GP7,GP2,GP5
OPTION GUI CONTROLS 76
OPTION TOUCH GP14,GP15
GUI CALIBRATE 0, 146, 253, 911, 667
OPTION SDCARD GP8
OPTION AUDIO GP27,GP26', ON PWM CHANNEL 5
RTC AUTO ENABLE OPTION

The error appears as if bit 7 in the control register is set to logic 1 and the oscillator is stopped.

This is from the DS3231-manual:




Best wishes! Joachim
 
v.lenzer
Regular Member

Joined: 04/05/2024
Location: Germany
Posts: 49
Posted: 09:05pm 06 May 2024
Copy link to clipboard 
Print this post

I have to apologize to you. I used the RTC DS1307 instead of a DS3231. I could have sworn it was a DS3231. I have lots of RTC in my craft box. I got the wrong one. With the DS3231 it now works without errors. Thank you for your support!
Best wishes! Joachim
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2075
Posted: 09:16pm 06 May 2024
Copy link to clipboard 
Print this post

check the battery.

I had an episode with some very poor coin cells (yellow ones about 1cm across and the voltage would drop to about 0.6V when on load (i.e. with the main power off), which is way below VBat (min 2.3V) required to keep things running without Vcc.

In such cases, the internal oscilator will stop and the registers become static. Check Reg 0Fh bit 7... "A logic 1 in this bit indicates that the oscillator either is stopped or was stopped for some period and may be used to judge the validity of the timekeeping data. This bit is set to logic 1 any time that the oscillator stops. The following are examples of conditions that can cause the OSF bit to be set:
1) The first time power is applied.
2) The voltages present on both VCC and VBAT are insufficient to support oscillation.
..."

case 2 was my problem - I think it might be yours too.

p.s. you have to reset the flag, it won't clear by itself.


google trnslation:
Überprüfen Sie die Batterie.

Ich hatte eine Episode mit einigen sehr schlechten Knopfzellen (gelbe mit einem Durchmesser von etwa 1 cm und die Spannung fiel unter Last (d. h. bei ausgeschaltetem Hauptstrom) auf etwa 0,6 V), was weit unter dem für die Aufrechterhaltung erforderlichen VBat (mindestens 2,3 V) liegt Dinge laufen ohne Vcc.

In solchen Fällen stoppt der interne Oszillator und die Register werden statisch. Check Reg 0Fh Bit 7... „Eine logische 1 in diesem Bit zeigt an, dass der Oszillator entweder gestoppt ist oder für einen bestimmten Zeitraum gestoppt wurde und kann zur Beurteilung der Gültigkeit der Zeitnehmungsdaten verwendet werden. Dieses Bit wird jederzeit auf logisch 1 gesetzt dass der Oszillator stoppt. Im Folgenden finden Sie Beispiele für Bedingungen, die dazu führen können, dass das OSF-Bit gesetzt wird:
1) Beim ersten Einschalten der Stromversorgung.
2) Die an VCC und VBAT anliegenden Spannungen sind unzureichend ausreichend, um die Schwingung zu unterstützen.
...“

Fall 2 war mein Problem – ich denke, es könnte auch Ihres sein.

p.s. Sie müssen das Flag zurücksetzen, es löscht sich nicht von selbst.
Edited 2024-05-07 07:20 by CaptainBoing
 
v.lenzer
Regular Member

Joined: 04/05/2024
Location: Germany
Posts: 49
Posted: 09:28pm 06 May 2024
Copy link to clipboard 
Print this post

Hello CaptainBoing!
After realizing that I wasn't using the DS3231 but the DS1307, I changed the modules but used the same battery. This means - as I wrote in the previous post - the RTC now works perfectly. In fact, the reason why the DS1307 did not work has not yet been found. It may be due to the weak battery. The DS3231 has enough voltage, the DS1307 may not. I also need to see if the DS1307 also has a control bit that can be used to turn off the oscillator.
The battery currently has an open circuit voltage of 3.07 V. Tomorrow I will test the DS1307 with a new CR2032.
Best wishes! Joachim
 
JanVolk
Senior Member

Joined: 28/01/2023
Location: Netherlands
Posts: 144
Posted: 09:54pm 06 May 2024
Copy link to clipboard 
Print this post

v.lenzer,

My experience with DS1307 is that the Vcc must be 5V, see manufacturer's PDF and disconnect the pullup resistors (SDA and SCL) because they are then connected to the 5V and external resistors SDA and SCL of 4k7 are connected to the 3V3.
When using Vcc=3V3 and a charging section with a diode(1n4148)and resistor the button cell will not charge sufficiently. Then use an external 3V button cell.

Jan
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2135
Posted: 10:10pm 06 May 2024
Copy link to clipboard 
Print this post

  Quote  My experience with DS1307 is that the Vcc must be 5V
Although the datasheet does say that, and for maximum accuracy is best, the DS1307 can operate at 3.3V if there is a voltage divider between the coin cell and the voltage sensing pin 3 = VBAT.
Some modules have the divider installed but others don't.

Edit. See this thread
Edited 2024-05-07 08:26 by phil99
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6783
Posted: 07:36am 07 May 2024
Copy link to clipboard 
Print this post

When the little yellow battery finally dies it's nice to recycle the module. I've started leaving PCB space for a CR2032 when I can, with a trace that runs close to the RTC position. When the yellow battery dies of old age, take it off and connect a short wire from the bat+ pad to the CR2032 trace, pop a battery in and off you go for a few years.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024