Hi, Im trying to use the DS3231 library into my 4 digits 7 segments LEDS, but results in lot of error, i only need to Read/write the Hour and minutes. on my code upon program starts i want to read the year, if it's not set then I'll write to the RTC registers. can someone kindly point what im doing wrong, here's the code :
Thank you
#chip16F18345, 16
#optionexplicit
#include<millis.h>
#include<DS3231.H>''Template comment at the start of the config file'
#startupInitPPS, 85
#definePPSToolPart16f18345SubInitPPS'Module: MSSP1SSP1DATPPS=0x0014'RC4 > SDA1RC4PPS=0x0019'SDA1 > RC4 (bi-directional)SSP1CLKPPS=0x0015'RC5 > SCK1RC5PPS=0x0018'SCK1 > RC5 (bi-directional)EndSub'Template comment at the end of the config file'' VariablesdimbHourasBytedimbSegmentasBytedimmS_CV, mS_LVasWorddimwCntrasworddimMultiplexasBytedimfFlashasbitdimhour, min, sec, yearasbytedimoldsecasbytedimdate, month, year, DOW, centuryasbyte' Defines
#defineSEG_APortb.7
#defineSEG_BPortb.6
#defineSEG_CPortc.7
#defineSEG_DPortc.1
#defineSEG_EPortc.2
#defineSEG_FPorta.0
#defineSEG_GPortb.5
#defineSEG_DPPortc.0'
#defineDIG_1PORTC.6
#defineDIG_2PORTA.2
#defineDIG_3PORTA.1
#DEFINEDIG_4PORTB.4' Port DirectionDirSEG_AoutDirSEG_BoutDirSEG_CoutdirSEG_DoutdirSEG_EoutDirSEG_FoutdirSEG_GoutdirSEG_DPout'DirDIG_1outDirDIG_2outdirDIG_3outDirDIG_4out'
#DefineMatch_ValPR2'PR2 is the timer 2 match registerMatch_Val=100'Interrupt afer 100 uSOninterrupttimer2MatchcallIntT2'Interrupt on matchInittimer2PS2_1, 1'Starttimer2'; Define Hardware I2C settings for SSP module
#defineHI2C_BAUD_RATE400
#defineHI2C_DATAPORTC.4
#defineHI2C_CLOCKPORTC.5;I2C pins need to be input for SSP moduleDirHI2C_DATAinDirHI2C_CLOCKin;MASTER I2C Device for SSP moduleHI2CModeMaster''read year,if year >=20 then RTC is initializedHI2CReStart; is DS3231 present?HI2CSend(DS_AddrRead)HI2CStopHI2CReceive(year, NACK)' DS3231_ReadDate(year)ifyear>=20thenUPDATE'READ TIME FROM rtcelseSEC=0MIN=30HOUR=18DOW=2DATE=28MONTH=4YEAR=20DS3231_ControlRegister=0DS3231_ControlStatus=0'HI2CReStart; is DS3231 present?HI2CSend(DS_AddrWrite)HI2CStopDS3231_SetClock(SEC,MIN,HOUR,DOW,DATE,MONTH,YEAR)DS3231_SetClock(DS3231_ControlRegister, DS3231_ControlStatus)ENDIF'' First scanbHour=0do'mS_CV=millis()ifmS_CV-mS_LV>=500then' required Time has Elapsedfflash=notfflashmS_LV=mS_CV'endififwcntr>=20000thenwCntr=0bhour=bHour+1ifbHour>9thenbHour=0Encode_Segmentendifloop'subroutinesSubIntT2wCntr=wCntr+1Multiplex=Multiplex+1ifMultiplex>4thenMultiplex=1SelectCaseMultiplexCase1setDIG_1onsetDIG_2offsetDIG_3offsetDIG_4offcase2setDIG_1offsetDIG_2onsetDIG_3offsetDIG_4offcase3setDIG_1offsetDIG_2offsetDIG_3onsetDIG_4offcase4setDIG_1offsetDIG_2offsetDIG_3offsetDIG_4onEndSelectEndSubsubEncode_Segment'common cathodeSelectCasebHourCase0bSegment=0b00000011Case1bSegment=0b10011111Case2bSegment=0b00100101Case3bSegment=0b00001101Case4bSegment=0b10011001Case5bSegment=0b01001001Case6bSegment=0b01000001Case7bSegment=0b00011111Case8bSegment=0b00000001Case9bSegment=0b00001001' case 10' bsegment = 0b11111110 'decimalpointEndSelectiffFlashthenbsegment=bsegment-1'SEG_A=bSegment.7SEG_B=bSegment.6SEG_C=bSegment.5SEG_D=bSegment.4SEG_E=bSegment.3SEG_F=bSegment.2SEG_G=bSegment.1SEG_DP=bSegment.0EndSubSubUPDATEEndSub
Last edit: Anobium 2020-04-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
define DS3231_ControlStatus 0x0F 'Control Status register
re...
DS3231_SetClock(DS3231_ControlRegister, DS3231_ControlStatus)
~~~
I am not sure what this call in meant to do. You have set the set the clock on the previous line.
Surely you need to read the time? Use DS3231_ReadTime(out DS_Hour, out DS_Min, out DS_Sec, out DS_A_P)or DS3231_ReadClock(out DS_Hour, out DS_Min, out DS_Sec, out DS_A_P, out DS_DOW, out DS_Date, out DS_Month, out DS_Year)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
"re...
DS3231_SetClock(DS3231_ControlRegister, DS3231_ControlStatus)
~~~
I am not sure what this call in meant to do. You have set the set the clock on the previous line."
I thought i still need to write the values to the RTC.
Ill go back to the board, ill revert back on result.
appreciate your help, Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have used the DS3231 many times and have never found problems, except for a defective one that had the incorrect 32.768KHz output.
Before using it, I advise you to initialize it as I did:
As with @JackJames, I've used the DS3231 in a number of projects. I simply copied and pasted the code from one of the demo files and, it, in an Apple style, "Just worked".
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, Im trying to use the DS3231 library into my 4 digits 7 segments LEDS, but results in lot of error, i only need to Read/write the Hour and minutes. on my code upon program starts i want to read the year, if it's not set then I'll write to the RTC registers. can someone kindly point what im doing wrong, here's the code :
Thank you
Last edit: Anobium 2020-04-28
DS3231_ControlRegister = 0
DS3231_ControlStatus = 0
~~~
define DS3231_ControlRegister 0x0E 'Control register
define DS3231_ControlStatus 0x0F 'Control Status register
DS3231_SetClock(DS3231_ControlRegister, DS3231_ControlStatus)
~~~
I am not sure what this call in meant to do. You have set the set the clock on the previous line.
Surely you need to read the time? Use
DS3231_ReadTime(out DS_Hour, out DS_Min, out DS_Sec, out DS_A_P)
orDS3231_ReadClock(out DS_Hour, out DS_Min, out DS_Sec, out DS_A_P, out DS_DOW, out DS_Date, out DS_Month, out DS_Year)
"re...
DS3231_SetClock(DS3231_ControlRegister, DS3231_ControlStatus)
~~~
I am not sure what this call in meant to do. You have set the set the clock on the previous line."
I thought i still need to write the values to the RTC.
Ill go back to the board, ill revert back on result.
appreciate your help, Thanks.
i still get errors, but it's ok for now. i just converted my old Proton code to GCB not using the library, here how it goes.
Define Hardware I2C settings for SSP module
#define HI2C_BAUD_RATE 400
#define HI2C_DATA PORTC.4
#define HI2C_CLOCK PORTC.5
;I2C pins need to be input for SSP module
Dir HI2C_DATA in
Dir HI2C_CLOCK in
;MASTER I2C Device for SSP module
HI2CMode Master
'
#define DS_AddrRead 0b11010001
#define DS_AddrWrite 0b11010000
'
'read year,if year >=20 then RTC is initialized
HI2CReStart ; is DS3231 present?
HI2CSend(DS_AddrRead)
HI2CReceive(ClockBuffer(6), NACK)
HI2CStop
'
if clockbuffer(6) >=20 then
UPDATE 'READ TIME FROM rtc
else
clockbuffer(0) = 0
clockbuffer(1) = 30
clockbuffer(2) = 18
clockbuffer(3) = 2
clockbuffer(4) = 28
clockbuffer(5) = 4
clockbuffer(6) = 20
clockbuffer(7)= 0 'Alarm1 Secs
clockbuffer(8)= 0x15 'alarm1 mins
clockbuffer(9)= 0x18 'alarm1 hours
clockbuffer(10)= 0x80 'a1am4 -alarm 1 when hours, mins, secs matched
clockbuffer(11) = 0x30 'alarm2 minutes
clockbuffer(12)= 5 'alarm2 hours
clockbuffer(13)= 0x80 'a2m4 alarm2 when hours and minutes matched
clockbuffer(14) = 0 'control
clockbuffer(15)= 0 'status
'
for i = 0 to 15
HI2CReStart
HI2CSend(DS_AddrWrite)
HI2CSend (i)
HI2CSend clockbuffer(i)
HI2CStop
next
END I
'
' First scan
bHour = 0
do
'
mS_CV = millis()
if mS_CV - mS_LV >= 500 then ' required Time has Elapsed
fflash = not fflash
I have used the DS3231 many times and have never found problems, except for a defective one that had the incorrect 32.768KHz output.
Before using it, I advise you to initialize it as I did:
Check it and then let me know.
As with @JackJames, I've used the DS3231 in a number of projects. I simply copied and pasted the code from one of the demo files and, it, in an Apple style, "Just worked".