Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Michael Miller
@Makuna
Ah, the module you have already has a resistor between VCC and the SQW pin. That's handy.
Leandro Boari
@leandrobnsilva
@Makuna, DS3231SquareWavePin_ModeBatteryBackup makes the SQW pin send low pulses of 1Hz intermittents.
And when the RTC is not supplied by VCC, it doesn't send alarm with low pulses.
:-(
Leandro Boari
@leandrobnsilva
I found a possible solution @Makuna! I'll test now...
They said:
To others who see this thread, the JChristensen library did not have a function to set the BBSQW pin so I wrote this one:
/*
Sets/resets the BBSQW pin in the control register
*/
byte DS3232RTC::setBBSQW(bool state)
{
    //Get original contents
    byte t = readRTC(RTC_CONTROL);
    if (state)
        //Set bit 6 i.e. the BBSQW
        t |= (1 << BBSQW);
    else
        t &= ~(1 << BBSQW);

    return (writeRTC(RTC_CONTROL, t));
}
Leandro Boari
@leandrobnsilva
Was the INTCN, A1IE & A2IE bits also set in the control register (0x0E) to enable the Alarm match to also trigger the interrupt?
Leandro Boari
@leandrobnsilva
So I modified the file RtcDS3231.h of your library and it worked!!!
case DS3231SquareWavePin_ModeAlarmOne:
            creg |= _BV(DS3231_BBSQW);
            creg |= _BV(DS3231_A1IE);
            break;
Michael Miller
@Makuna
Do you want to make a pull request with the changes and I will review and merge it?
Michael Miller
@Makuna
So the BBSQW is NOT to test for vcc<vb, but to just enable the square wave output for alarms and others when in this state.
Michael Miller
@Makuna
I think I am going to change the method a little with this newly learned information. This is what I will be, what do you think?
void SetSquareWavePin(DS3231SquareWavePinMode pinMode, bool enableWhileInBatteryBackup)
    {
        uint8_t creg = getReg(DS3231_REG_CONTROL);

        // clear all relevant bits to a known "off" state
        creg &= ~(DS3231_AIEMASK | _BV(DS3231_BBSQW));
        creg |= _BV(DS3231_INTCN);  // set INTCN to disables clock SQW

        if (enableWhileInBatteryBackup && pinMode != DS3231SquareWavePin_ModeNone )
        {
            creg |= _BV(DS3231_BBSQW); // set enable int/sqw while in battery backup flag
        }

        switch (pinMode)
        {
        case DS3231SquareWavePin_ModeNone:
            break;

        case DS3231SquareWavePin_ModeClock:
            creg &= ~_BV(DS3231_INTCN); // clear INTCN to enable clock SQW 
            break;

        case DS3231SquareWavePin_ModeAlarmOne:
            creg |= _BV(DS3231_A1IE);
            break;

        case DS3231SquareWavePin_ModeAlarmTwo:
            creg |= _BV(DS3231_A2IE);
            break;

        case DS3231SquareWavePin_ModeAlarmBoth:
            creg |= _BV(DS3231_A1IE) | _BV(DS3231_A2IE);
            break;
        }

        setReg(DS3231_REG_CONTROL, creg);
    }
Leandro Boari
@leandrobnsilva
Sorry for the delay. Great, that's it! It worked very well.
Bastian J├Ąger
@miseryofdevice
@m1ch3l4 Did you solve it? I think I am facibg the same problem and maybe I am just to stupid to find the right Pins to replace 19 and 4 for my ESP12f.
Right niw my DS3231 can not wake up the ESP12f and there is no clear example on solving this.
shyney7
@shyney7
Hi, Im trying to get the epoch time as a float from the DS3231 but I'm not able to. I'm able to get the day,month etc as an integer like in this Code:
RtcDateTime currentTime = rtcObject.GetDateTime();    //get the time from the RTC


    char str[20];   //declare a string as an array of chars

    sprintf(str, "%d.%d.%d,%d:%d:%d,",     //%d allows to print an integer to the string
          currentTime.Day(),    //get day method
          currentTime.Month(),  //get month method
          currentTime.Year(),   //get year method
          currentTime.Hour(),   //get hour method
          currentTime.Minute(), //get minute method
          currentTime.Second()  //get second method
         );
but if I try float current = currenttime.TotalSeconds(); or float current = currenttime.Epoch32Time(); it doesnt work
Michael Miller
@Makuna
because its not a float and a float will not represent the value accurately. Why do you need it as a float?
Michael Miller
@Makuna
Epoch time is best as either a unsigned 32 bit integer or unsigned 64 bit integer.
Converting/casting this to float will loose time precision.
What do you mean by "it doesn't work"? It doesn't compile? It doesn't give you a value you expected?
Leandro Boari
@leandrobnsilva
Hi, @Makuna!
I'm here again. We figured out how to make the alarm pulses by Vbat power supply. But the alarm trigger is logic 0. I really need it to be in logic 1! The implementation of NOT GATES has considerable consumption.

The DS3231 documentation says:

Active-Low Interrupt or Square-Wave Output. This open-drain pin requires an external pullup resistor connected to a supply at 5.5V or less. This multifunction pin is determined by the state of the INTCN bit in the Control Register (0Eh). When INTCN is set to logic 0, this pin outputs a square wave and its frequency is determined by RS2 and RS1 bits. When INTCN is set to logic 1, then a match between the timekeeping registers and either of the alarm registers activates the INT/SQW pin (if the alarm is enabled). Because the INTCN bit is set to logic 1 when power is first applied, the pin defaults to an interrupt output with alarms disabled. The pullup voltage can be up to 5.5V, regardless of the voltage on VCC. If not used, this pin can be left unconnected.

Leandro Boari
@leandrobnsilva
image.png
And here the circuit of the DS3231. Is there any way?
Michael Miller
@Makuna
The chip doesn't support it. And for your case, specifically be low power? I am not familiar enough on the subject of this sort of circuit design to know the answer.
zekageri
@zekageri
Hi!
I try to set the date and time on my RTC ds3231 with makuna RTC lib. Iam processing an input from my esp32 web interface as a String like this:
2019-07-10T13:33
I make some int variable from it to set the time for the RTC like this:
server.on("/IdoBeallit", HTTP_ANY, {
request->send(204);
if (request->hasArg("Ido")){
String Idocske = request->arg("Ido");
Serial.println(Idocske);
uint16_t Ev = Idocske.substring(0,4).toInt();
Idocske.remove(0, 5);
uint16_t Honap = Idocske.substring(0,2).toInt();
Idocske.remove(0, 3);
uint16_t Nap = Idocske.substring(0,2).toInt();
Idocske.remove(0, 3);
uint16_t Ora = Idocske.substring(0,2).toInt();
Idocske.remove(0, 3);
uint16_t Perc = Idocske.substring(0,2).toInt();
Idocske.remove(0, 2);
uint16_t sec = 0;
tudunk_nezni = false;
Rtc.SetDateTime(RtcDateTime(Ev,Honap,Nap,Ora,Perc,sec));
tudunk_nezni = true;
}
});
And the RTC sometimes set the time as i requested, sometimes it is not doing anything, but sometimes , which is my issue, the ESP crashes and Restarts itself. My other i2c devices working fine. (Currently 5 with the ds3231)
My variables looks like these:
Ev = 2019 (Year)
Honap = 7 (Month)
Nap = 10 ( Day )
Ora = 13 ( Hour )
Perc = 50 ( Min )
Sec = 0 or 00 ( I dont need this )
zekageri
@zekageri

Crash error:
codeGuru Meditation Error: Core 0 panic'ed (IntegerDivideByZero). Exception was
was unhandled.
Core 0 register dump:
PC : 0x400f3635 PS : 0x00060f30 A0 : 0x800f3a7c A1 : 0 : 0x3ffd50e0
A2 : 0x00000020 A3 : 0x3ffd516c A4 : 0x00000032 A5 : 0 : 0x3ffbec44
A6 : 0x00004e20 A7 : 0x00000000 A8 : 0x800f362d A9 : 0 : 0x3ffd50c0
A10 : 0x00000000 A11 : 0x00000000 A12 : 0x3ffb31f8 A13 : 0 : 0x3ffc3cf0
A14 : 0x00002710 A15 : 0x3ffbec44 SAR : 0x00000013 EXCCAUSE: 0E: 0x00000006
EXCVADDR: 0x00000000 LBEG : 0x4000c46c LEND : 0x4000c477 LCOUNT : 0 : 0x00000000

Backtrace: 0x400f3635:0x3ffd50e0 0x400f3a79:0x3ffd5110 0x400edbe5:0x3ffd5130130 0x400edc99:0x3ffd5160 0x400edd1d:0x3ffd5190 0x400d3377:0x3ffd51b0 0x44f7:00ec4f7:0x3ffd5220 0x400ea277:0x3ffd5260 0x400ea31d:0x3ffd52a0 0x400ea5752f0:0x3ffd52f0 0x40157cc9:0x3ffd5310 0x40157dd5:0x3ffd5350 0x401583fe:0x3ffd789:5370 0x40089789:0x3ffd53a0 code

Decoded:
'code'

PC: 0x400f3635
EXCVADDR: 0x00000000

Decoding stack results
0x40089789: vPortTaskWrapper at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/port.c line 143

'code'

Michael Miller
@Makuna
@zekageri This file "port.c" is not in my library. further, it is not in my Esp32 Arduino install, I also could not find anything with "taskwrapper" in the Esp32 Arduino code base. I would suggest looking at that line and see what its doing.
I suspect you can't call any of the WIRE methods within the web callback (a common problem with system level callbacks). Ask on the Esp32 gitter channel about calling Wire methods on that callback.
Michael Miller
@Makuna
Also, what version of the Arduino Esp32 core are you using?
zekageri
@zekageri
Thank you for your answer. I'am using espressif32 1.8.0 currently because the OTA update did not work with 1.9.0 for some reason. Iam in platformIO inside VSCODE. What do you mean that wire methods does not work in web callbacks? It is sometimes sets the time and sometimes goes with a crash. But if it is true i can see if i set the time from the loop with a flag.
zekageri
@zekageri
Okay i think that was the problem. If i set a flag in the web callback and watch that flag in the loop and set the time when the request setted the flag everything is working fine. God bless you Makuna. I did not know that Wire methods does not work in web callbacks. :O
Michael Miller
@Makuna
@zekageri I would ask on the Esp32 gitter channel if there is a solution for this. There maybe something simple that makes the callback more usable. The Esp32 is a dual core processor and some issues are that the callbacks happen on a different core.
zekageri
@zekageri
Yeah, that is true. I had some issues because of the 2 cores in the past. The 0. core is totally useless if you want to run a complex async webserver. You can use your "first" core as usual if you do that. I tried to measure a 8Khz frequency on core0, and all my web things was slow A.F. But thats okay if you want to almost totally full one of the cores. But if i run something simplier on core0 , the web things are slow A.F again. If it is not a blink function, than that core is just for the web handlings.
Boris van Galvin
@vangalvin
I just had some fun with the WiFi D1 Mini RTC and Micro SD board. There is a resistor and diode acreoss the battery. Not quite sure what its puropose is other than maybe pulling the voltage down if the battery is stuck in the wrong way.
Anyway the Diode shorts the battery. So removed that and the resistor and its working perfectly with the library thanks. :)
I do have to however ask, how do you get just the EPOCH time? I was looking at using this to timestamp sensors.
Michael Miller
@Makuna
@vangalvin once you have the RtcDateTime, just call Epoch32Time() or Epoch64Time() on that object to get what you want.
Its listed here in the wiki
Boris van Galvin
@vangalvin
Awesome, Yep got that thanks :) works a treat!
Just as a heads up the unit is heading down to Antartica to be installed on the side of Mt Erebus and will be collecting temperature data. there are about 60+ temperature sensors per node.
Michael Miller
@Makuna
Is there a public web site on your project? I like to add links to the wiki to projects people do with my libraries.
Boris van Galvin
@vangalvin
Sadly not as yet. I may end up making one at some stage however due to time constraints and I am having issues finding the time to get all the electronics built, design and machine the housing and get the programming done. lol. 8AM starts and its justgone 3AM and im still up working. Man i wish the hours were billable :P
Bashar3
@Bashar3
Hi I'm having trouble with showing the right time using the method "RtcDateTime now = rtcModule.GetDateTime();" it's showing wrong hour and wrong minute. I'm using Arduino Uno.I'm trying to print the time to an oled display. my method updateTime() looks like this:

void updateTime(){

oldMinute = minutes;
RtcDateTime now = rtcModule.GetDateTime();

hours = now.Hour();
minutes = now.Minute();
seconds = now.Second();

Bashar3
@Bashar3
the sketch I'm building exists in this code in GitHub also https://github.com/kjellcompany/Arduino_701/blob/master/GrandFinale/GrandFinale.ino
Michael Miller
@Makuna
@Bashar3 Are you sure that you set the date and time on the module?
While I saw nothing obviously wrong with your code; I would suggest that you look at the examples I provide and add at least a little of the checking code; like making sure the RTC is even running and that the datetime and is valid.
Bashar3
@Bashar3
@Makuna I'll take a look at it, appreciate your answer.