RTC DS3231

hello there! i wants to get millisecond in return as a timestamp using RTC DS3231, can anyone help me how can i solve this issue?
as i am already able to get the local time from my laptop using RTC DS3231.

You have to create a ms timer yourself after each 1s elapses from the DS3231.

i dont get it . Sorry i am a newbie ,can you point out some links or sample code.

The RTC does not supply milliseconds, at best seconds.

The RTC can output an accurate 1 Hz square wave, which you can read with an Arduino pin and use for timing.

What are you trying to do?

how can i use the 1 hz square for timing, i dont get the solution anywhere for the milliseconds using rtc ds3231

Timing what?

raza505050:
how can i use the 1 hz square for timing, i dont get the solution anywhere for the milliseconds using rtc ds3231

Here is a link to the spec sheet https://datasheets.maximintegrated.com/en/ds/DS3231.pdf that explains what the device does. Which one of the thing do's do you want?

You can get a 1Hz square wave or a 32kHz square wave or a interrupt. Of course you can read the device and get the time, as well.

A 1Hz squarewave is 1000mS and a 32Khz square wave is a whole lot of millisecods.

Are you wanting to convert the time to milliseconds?

If you just want milli seconds you can use the Arduino function called millis() and not even require an external device.

I HAVE THIS CODE, I CAN GET THE CURRENT TIME, BUT I AM UNABLE TO RECIEVE THE MILLISECONDS.
I NEED MILLIS BECAUSE I HAVE THE UDP PACKETS TRANSFER CODE, WHERE I WANTS THE TIMESTAMP IN MILLIS, SO THAT I COULD USE THAT FOR MY TDOA OR TOF ALGO

// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include “RTClib.h”
#define InterruptPin 13

volatile uint32_t lcnt = 0;
RTC_DS3231 rtc;

char daysOfTheWeek[7][12] = {“Sunday”, “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”};

void setup () {

//#ifndef ESP8266
// while (!Serial); // for Leonardo/Micro/Zero
//#endif

Serial.begin(115200);

// delay(3000); // wait for console opening

if (! rtc.begin()) {
Serial.println(“Couldn’t find RTC”);
while (1);
}
pinMode(InterruptPin, INPUT_PULLUP);
if (rtc.lostPower()) {
Serial.println(“RTC lost power, lets set the time!”);
// following line sets the RTC to the date & time this sketch was compiled
// rtc.adjust(DateTime(F(DATE), F(TIME)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
attachInterrupt(digitalPinToInterrupt(InterruptPin), fcnt, FALLING);
}

void loop () {
DateTime now = rtc.now();
static uint32_t ts = millis();
uint32_t a = millis();
if (a - ts >= 1000) {
ts = a;
noInterrupts();
// uint32_t currentCount = lcnt;
// lcnt = 0;
// interrupts();
// Serial.println(currentCount);
// }

// unsigned long a=millis();
// if (a<1000){
noInterrupts();

Serial.println(lcnt);
}

// Serial.print(now.year(), DEC);
// Serial.print(’/’);
// Serial.print(now.month(), DEC);
// Serial.print(’/’);
// Serial.print(now.day(), DEC);
// Serial.print(" (");
// Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
// Serial.print(") “);
// Serial.print(now.hour(), DEC);
// Serial.print(’:’);
// Serial.print(now.minute(), DEC);
// Serial.print(’:’);
// Serial.print(now.second(), DEC);
// Serial.println();
//
// Serial.print(” since midnight 1/1/1970 = ");
// Serial.print(now.unixtime());
// Serial.print("s = ");
// Serial.print(now.unixtime() / 86400L);
// Serial.println(“d”);

// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now + TimeSpan(0,0,5,0));

// Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print(’/’);
Serial.print(future.month(), DEC);
Serial.print(’/’);
Serial.print(future.day(), DEC);
Serial.print(’ ‘);
Serial.print(future.hour(), DEC);
Serial.print(’:’);
Serial.print(future.minute(), DEC);
Serial.print(’:’);
Serial.print(future.second(), DEC);
Serial.println();

// Serial.print(“Temperature: “);
// Serial.print(rtc.getTemperature());
// Serial.println(” C”);

Serial.println();
delay(1000);
}
void fcnt(){
lcnt+=1;
}

Please edit your post to add code tags

Just fill in the millisecond field of the timestamp with zeros, and you should be fine.