HELP WITH DS3231 to read time using PicAxe

Is there anyone out there who has used a DS3231 RTC using a Picaxe programming code I could work with to try and understand this more sorry in advice very new to this and right in the deep end

Thanks in advance :)

even a Friendly chat would help
 
Can anyone help with is code only problem is that it dose not no about 28 days or 30/31 days in a month is there anyone who can have a look few my code and maybe point me in the right direction

Kind Regards
Chris


#rem

I2C DS1307 / DS3231 RTC set / test program
Note. the data to/from RTC is in BCD format
2400,8,N,1 OLED / LCD on pin c.4

HIT PROGRAM 20 SEC BEFORE ACTUAL TIME

#endrem

; Funktioniert FAST --- Anzeige Tag, Datum so weit ok,
; Uhrzeit - seltsame Spr?nge
; Anzeige Interne Spannung --> OK!

#picaxe 08M2
#no_data
;#terminal 4800

symbol baud = N2400
symbol oled = C.4
symbol seconds = b0
symbol mins = b1
symbol hour = b2
symbol day = b3
symbol date = b4
symbol month = b5
symbol year = b6
symbol control = b7
;symbol temp = b8

init:
hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte ;set RTC slave address
pause 800
serout oled,baud,(254,1)
pause 100


;uncomment the line below to update the clock time

goto set_clock


main: ;read time and date, send to display
do

hi2cin 0,(seconds,mins,hour,day,date,month,year)
pause 100
bcdtoascii seconds,b10,b11
bcdtoascii mins,b12,b13
bcdtoascii hour,b14,b15
bcdtoascii date,b16,b17
bcdtoascii month,b18,b19
bcdtoascii year,b20,b21

select case day ;converts 'day' variable to day of week for display
case 1 serout oled,baud,(254,128," Mo ")
case 2 serout oled,baud,(254,128," Tu")
case 3 serout oled,baud,(254,128," We ")
case 4 serout oled,baud,(254,128," Th ")
case 5 serout oled,baud,(254,128," Fr ")
case 6 serout oled,baud,(254,128," Sa ")
case 7 serout oled,baud,(254,128," Su ")
endselect
serout oled,baud,(254,133,b16,b17,".",b18,b19,".20",b20,b21) ;positioned for 20X4 or
pause 500
serout oled,baud,(254,193,b14,b15,":",b12,b13,":",b10,b11) ;16X2 char display

calibadc10 w2
w2 = 10486/w2
bintoascii w2,b6,b7,b8
serout C.4,baud,(254,203)
Sertxd (b14,b15,":",b12,b13,":",b10,b11, cr,lf)
Debug
pause 800
loop

set_clock: ;write time and date e.g. 08:52:00 on Sat 01/03/14
;Monday is day 1, Sunday is day 7
let seconds = $00 ;00 secs
let mins = $26 ;00 mins
let hour = $11 ;00 hours
let day = $01 ;05 day of week
let date = $30 ;30day
let month = $05 ;05 month
let year = $2022 ;22 year
let control = %00010000 ;Enable output at 1Hz

hi2cout 0,(seconds,mins,hour,day,date,month,year,control)

goto main
 

Flenser

Senior Member
only problem is that it dose not no about 28 days or 30/31 days in a month
I've never used one of these DS3231 RTC chips but the datasheet makes this comment on the first page:
"The RTC maintains seconds, minutes, hours, day, date, month, and year information. The date at the end of the month is automatically adjusted for months with fewer than 31 days, including corrections for leap year."

Your PICAXE program does not need to know about the number of days in a month. This is being taken care of by the DS3231 RTC chip.
 

hippy

Technical Support
Staff member
As noted, a correctly set RTC will handle day and dates automatically. If you can explain what is not right, show the results you are seeing and indicate how that's different to what's expected, that may help identify what the issue is.
 
I've never used one of these DS3231 RTC chips but the datasheet makes this comment on the first page:
"The RTC maintains seconds, minutes, hours, day, date, month, and year information. The date at the end of the month is automatically adjusted for months with fewer than 31 days, including corrections for leap year."

Your PICAXE program does not need to know about the number of days in a month. This is being taken care of by the DS3231 RTC chip.

Thank you for this as I very much appreciate you time even to reply I did see it in the Datasheet but I am new to my programming career and see a lot of people like yourself I can benefit from you knowledge.

Kind Regards Thanks again
Chris
 
As noted, a correctly set RTC will handle day and dates automatically. If you can explain what is not right, show the results you are seeing and indicate how that's different to what's expected, that may help identify what the issue is.

Thanks Hippy I do see You the man regarding these forums!

as I said to Flenser thank you for your reply and I will sure take all the knowledge to all bring to these pages as a new be to my programming career its great to see like minded people about and very encouraging to me to pursue this and cant wait to see where I end up.

thanks again hippy and everyone who has contributed to my first proper forum


UPDATE

I have completed this task and I have running RTC with the correct time correct day and running on a screen.

so thank you all Again you all have been a great help if not in this forum but guiding me in the right direction.

:)
 
Top