Hot!DS3231 and BCD time and calendar format

Page: 12 > Showing page 1 of 2
Author
SweetOrange
Senior Member
  • Total Posts : 159
  • Reward points : 0
  • Joined: 2011/07/24 10:51:46
  • Location: Athens Greece
  • Status: offline
2018/02/06 03:04:32 (permalink)
0

DS3231 and BCD time and calendar format

Hi!
I want to convert the BCD format of time and calendar (of DS3231) to two hex bytes.
I went to this site: http://www.piclist.com/techref/microchip/math/radix/index.htm
So which conversion do I need?
 
thanks
#1

25 Replies Related Threads

    1and0
    Access is Denied
    • Total Posts : 8486
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: DS3231 and BCD time and calendar format 2018/02/06 04:08:44 (permalink)
    +1 (1)
    Give an example of what you want to convert.  Asm or C?
     
    #2
    SweetOrange
    Senior Member
    • Total Posts : 159
    • Reward points : 0
    • Joined: 2011/07/24 10:51:46
    • Location: Athens Greece
    • Status: offline
    Re: DS3231 and BCD time and calendar format 2018/02/06 04:22:21 (permalink)
    0
    I want the conversion code to be in asm.
    In the Ds3231 datasheet it is mentioned that "The contents of the time and calendar registers
    are in the binary-coded decimal (BCD) format".
    So taking into regards the website I mentioned above do I need Packed BCD to 16 bit binary conversion 
    or Unpacked BCD to 16 bit binary conversion?

    Attached Image(s)

    #3
    1and0
    Access is Denied
    • Total Posts : 8486
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: DS3231 and BCD time and calendar format 2018/02/06 04:28:32 (permalink)
    +1 (1)
    I don't have the time now to read the DS3231 datasheet. It depends on whether the BCD number is packed or unpacked. "Hex bytes" do not necessary mean the same as "binary". So again, give an example of the value(s) before and after conversion.
    #4
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: DS3231 and BCD time and calendar format 2018/02/06 05:14:48 (permalink)
    0
    RTC registers are "Packed BCD", meaning that there are two BCD digits in each byte.
    I assume you want binary output, e.g. 12 noon, stored as "0x12", would be converted to 0x0C
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #5
    1and0
    Access is Denied
    • Total Posts : 8486
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: DS3231 and BCD time and calendar format 2018/02/06 05:28:44 (permalink)
    0
    If that is the case, you will need 2-digit packed BCD to 8-bit binary conversion. This one should work: http://www.piclist.com/te...th/radix/bp2b-2d8b.htm
    #6
    rodims
    Super Member
    • Total Posts : 1377
    • Reward points : 0
    • Joined: 2009/02/10 11:08:59
    • Location: 51.9627, 7.6262
    • Status: online
    Re: DS3231 and BCD time and calendar format 2018/02/06 05:33:00 (permalink)
    0
    Looking into the data sheet, especially the posted image of OP, the chip uses packed BCD but also uses upper bits to store even more information like 12/24 h mode or century. 
    So you can use the conversion code as a starting point, but you need to take care and mask off the upper BCD nibble bits.
    #7
    SweetOrange
    Senior Member
    • Total Posts : 159
    • Reward points : 0
    • Joined: 2011/07/24 10:51:46
    • Location: Athens Greece
    • Status: offline
    Re: DS3231 and BCD time and calendar format 2018/02/06 07:01:23 (permalink)
    0
    Hi!
    I am a bit confused.
    I have attached an image file of the i2c communication between the PIC and the
    DS3231.
    In my software I do the following:
    1) I write the slave address (0x68) of DS3231 with a WRITE bit (low)  and wait for aknowledge
    2) I write the register address (0x00) of DS3231 and wait for aknowledge
    3) I write the slave address (0x68) of DS3231 with a READ bit (high) and wait for aknowledge
    4) Read the Seconds and wait for aknowledge.
     
    This is interpreted to four bytes in total and this is what i see in my scope but the value of the
    slave address is wrong and the aknowledge is high (it should be low).
    Unless I am interpret it wrong.
     
    Do I need to initialize the Seconds register?

    Attached Image(s)

    #8
    rodims
    Super Member
    • Total Posts : 1377
    • Reward points : 0
    • Joined: 2009/02/10 11:08:59
    • Location: 51.9627, 7.6262
    • Status: online
    Re: DS3231 and BCD time and calendar format 2018/02/06 07:38:53 (permalink)
    0
    Did you yet perform any successful read from the chip ?
    It looked as if you can already communicate with the chip and only the BCD format was your problem.
    Which is your PIC and what is your code ? (use code tags)
    Who should write the seconds, if not you ?
    #9
    davekw7x
    Entropy++
    • Total Posts : 1575
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Left Coast, USA
    • Status: offline
    Re: DS3231 and BCD time and calendar format 2018/02/06 09:20:31 (permalink)
    +1 (1)
    SweetOrange
    In my software I do the following:
    1) I write the slave address (0x68) of DS3231 with a WRITE bit (low)  and wait for aknowledge
    2) I write the register address (0x00) of DS3231 and wait for aknowledge
    3) I write the slave address (0x68) of DS3231 with a READ bit (high) and wait for aknowledge
    4) Read the Seconds and wait for aknowledge.

    Hmm...
    7-bit Device Address = 0b1101000

    Control byte for writing = 0b11010000
    Control byte for reading = 0b11010001

    Your step 1:
    According to my tired old eyes, the first control byte on your scope seems to be 0b10000100
    This was not acknowledged.
     
    Your step 2:
    This was not acknowledged.

    Your step 3:
    The second control byte on your scope seems to be 0b10000101
    This was not acknowledged.
     
    Your step 4:
    Since the device did not acknowledge the control byte of step3, it did not respond to the read command, and SDA remains high for the transfer.
    [Edit]
    Note that, since the received value, 0xFF, is not a valid representation of two BCD digits, the conversion information you originally asked for won't help until you can read valid data from the chip.
    [/Edit]

    I think you have done the start, restart, stop stuff correctly, but it might be more instructive to see your code.

    Also, some people implement their I2C read/write functions to take the 7-bit Device ID byte as a parameter, then shift it left one bit and make the lsb equal to 1 for reading, zero for writing.  Others take the full eight-bit control byte and transmit it exactly as it gets it from the calling program.

    Bottom line: You tell us what you want to do, and you show us what it is doing.  Since it is not doing what you want it to do, you have to fix your program.  If you can't understand why the problem manifests itself and you want some help, you should show us the code.


    Regards,

    Dave


    post edited by davekw7x - 2018/02/06 10:24:57

    Sometimes I just can't help myself...
    #10
    BMD
    Super Member
    • Total Posts : 427
    • Reward points : 0
    • Joined: 2003/12/02 21:42:52
    • Location: UK
    • Status: offline
    Re: DS3231 and BCD time and calendar format 2018/02/06 09:20:31 (permalink)
    +1 (1)
    Hi,
    The slave address in the first byte is wrong, therefore a Nack is received. 
     
    Theres no point in doing anything more, the link is talking to nobody.
    You need to look at why you are passing the wrong address to the I2C buffer after the start.

    Regards

    Brandon
    #11
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2745
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: DS3231 and BCD time and calendar format 2018/02/06 10:09:32 (permalink)
    0
    Make a function that can get a string from the i2c device then dump all 19 registers to a pointer to an array.  16bit only.
    .include "DS3231RTCLib2.inc"
    .globl _rtc_dumpregisters
    .section DS3231RTC,code
    ;----------------------------------------------------
    .equ arg_Resisters, w0

    _rtc_dumpregisters:
        mov        arg_Resisters,w2
        mov        #I2C_DS3231_RTC,w0
        mov        #RTC_SECONDS,w1
        mov        #19,w3
        rcall   _getsI2C
        return
    ;----------------------------------------------------
    .end


    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #12
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2745
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: DS3231 and BCD time and calendar format 2018/02/06 10:21:39 (permalink)
    0
    The address of this chip is $D0 (bits 7:1),  bit 0 is the RD/NOT WR bit.
     

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #13
    Nikolay_Po
    Super Member
    • Total Posts : 1714
    • Reward points : 0
    • Joined: 2012/04/01 13:49:27
    • Location: Russia, Novorossiysk
    • Status: online
    Re: DS3231 and BCD time and calendar format 2018/02/06 13:20:23 (permalink)
    +1 (1)
    Here is my data structure DS3231M integrated module I've made from the datasheet description:
    typedef union {
        uint8_t Bytes[19]; //As a byte payload
        struct { //As named registers
            struct { //0x00 and 0x01 addresses, Seconds and Minutes registers
                unsigned Seconds : 4;
                unsigned Seconds10 : 3; //Tens of seconds
                unsigned reserved1 : 1;
                unsigned Minutes : 4;
                unsigned Minutes10 : 3; //Tens of minutes
                unsigned reserved2 : 1;
            } SecMin;
     
            union { //0x02 and 0x03 addresses, Hours and Day registers
                struct { //24-hours variant
                    unsigned Hours : 4;
                    unsigned Hours10 : 1; //Plus 10 hours
                    unsigned Hours20 : 1; //Plus 20 hours
                    unsigned TwelveNot24 : 1; //12 or 24 hours format
                    unsigned reserved1 : 1;
                    unsigned Day : 3;
                    unsigned reserved2 : 5;
                } Hrs24;
                struct { //12-hours variant
                    unsigned Hours : 4;
                    unsigned Hours10 : 1; //Plus 10 hours
                    unsigned PMnotAM : 1; //PM
                    unsigned TwelveNot24 : 1; //12 or 24 hours format
                    unsigned reserved1 : 1;
                    unsigned Day : 3;
                    unsigned reserved2 : 5;
                } Hrs12;
            } DayHrs;

            struct { //0x04 and 0x05 addresses, Date (day of month), month and century
                unsigned Date : 6;
                unsigned reserved1 : 2;
                unsigned Month : 5;
                unsigned reserved2 : 2;
                unsigned Century : 1;
            } DateMonthCent;

            struct { //0x06 address, Years
                unsigned Years : 4;
                unsigned Years10 : 4; //Tens of years
            } Years;

            struct { //0x07 address, Alarm 1 Seconds
                unsigned Seconds : 4;
                unsigned Seconds10 : 3; //Tens of seconds
                unsigned A1M1 : 1; //Alarm 1 mask, bit 1
            } Al1Sec;

            struct { //0x08 address, Alarm 1 Minutes
                unsigned Minutes : 4;
                unsigned Minutes10 : 3; //Tens of minutes
                unsigned A1M2 : 1; //Alarm 1 mask, bit 2
            } Al1Min;

            union { //0x09 address, Alarm 1 Hours
                struct { //24-hours variant
                    unsigned Hours : 4;
                    unsigned Hours10 : 1; //Plus 10 hours
                    unsigned Hours20 : 1; //Plus 20 hours
                    unsigned TwelveNot24 : 1; //12 or 24 hours format
                    unsigned A1M3 : 1; //Alarm 1 mask bit 3
                } F24h;
                struct { //12-hours variant
                    unsigned Hours : 4;
                    unsigned Hours10 : 1; //Plus 10 hours
                    unsigned PMnotAM : 1; //PM
                    unsigned TwelveNot24 : 1; //12 or 24 hours format
                    unsigned A1M3 : 1; //Alarm 1 mask bit 3
                } F12h;
            } Al1Hrs;

            struct { //0x0A address, Alarm 1 Day
                unsigned DayOrDate : 5; //Day of week or date (day of month)
                unsigned DYnotDT : 1; //Day of week if set. Else date of month
                unsigned A1M4 : 1; //Alarm 1 mask bit 4
            } Al1Day;

            struct { //0x0B address, Alarm 2 Minutes
                unsigned Minutes : 4;
                unsigned Minutes10 : 3; //Tens of minutes
                unsigned A2M2 : 1; //Alarm 2 mask, bit 2
            } Al2Min;

            union { //0x0C address, Alarm 2 Hours
                struct { //24-hours variant
                    unsigned Hours : 4;
                    unsigned Hours10 : 1; //Plus 10 hours
                    unsigned Hours20 : 1; //Plus 20 hours
                    unsigned TwelveNot24 : 1; //12 or 24 hours format
                    unsigned A2M3 : 1; //Alarm 2 mask bit 3
                } F24h;
                struct { //12-hours variant
                    unsigned Hours : 4;
                    unsigned Hours10 : 1; //Plus 10 hours
                    unsigned PMnotAM : 1; //PM
                    unsigned TwelveNot24 : 1; //12 or 24 hours format
                    unsigned A2M3 : 1; //Alarm 2 mask bit 3
                } F12h;
            } Al2Hrs;

            struct { //0x0D address, Alarm 2 Day
                unsigned DayOrDate : 5; //Day of week or date (day of month)
                unsigned DYnotDT : 1; //Day of week if set. Else date of month
                unsigned A2M4 : 1; //Alarm 2 mask bit 4
            } Al2Day;

            struct { //0x0E address, Control register
                unsigned A1IE : 1; //Alarm 1 interrupt enable
                unsigned A2IE : 1; //Alarm 2 interrupt enable
                unsigned INTCN : 1; //Interrupt control
                unsigned reserved : 2;
                unsigned CONV : 1; //Convert temperature
                unsigned BBSQW : 1; //Battery-backed square wave enable
                unsigned notEOSC : 1; //Inverse Oscillator Enable bit
            } Control;

            struct { //0x0F address, Status register
                unsigned A1F : 1; //Alarm 1 flag
                unsigned A2F : 1; //Alarm 2 flag
                unsigned BSY : 1; //Device is busy by temperature conversion
                unsigned EN32KHZ : 1; //Enable 32.768kHz output
                unsigned reserved : 3;
                unsigned OSF : 1; //Oscillator fault flag
            } Status;
            int8_t Offset; //0x10 address, aging offset register
            int16_t Temperature; //0x11 and 0x12 addresses, temperature value
            //one count is 1/256 degrees of Celsius. Resolution is 0.25 degree.
        } Regs;
    } Timekeeping_t;

    I've checked, the temperature value was correct. So it seems I haven't miss a byte. This structure was quite convenient when I've used it for DS3231 coding thanks to MPLAB X IDE autocompletion hints.
    #14
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2745
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: DS3231 and BCD time and calendar format 2018/02/06 15:07:37 (permalink)
    +1 (1)
    I did not find a reason to use a structure with the DS3231, instead 32bit longs are enough.
     
    Here are my header files.  It probably will not be aligned on the forum.
    //----------------------------------------------------
    #ifndef DS3231RTCLIB2_H
    #define    DS3231RTCLIB2_H
    //----------------------------------------------------
    #define I2C_DS1307_RTC          0xd0 //Maxim real time clock
    #define I2C_DS3231_RTC          0xd0 //Maxim Extremely Accurate real time clock
    //----------------------------------------------------
    //registers
    #define RTC_SECONDS             0x00
    #define RTC_MINUTES             0x01
    #define RTC_HOURS               0x02
    #define RTC_DAY                 0x03
    #define RTC_DATE                0x04
    #define RTC_CENTURY_MONTH       0x05
    #define RTC_YEAR                0x06
    #define RTC_ALARM1_SECONDS      0x07
    #define RTC_ALARM1_MINUTES      0x08
    #define RTC_ALARM1_HOURS        0x09
    #define RTC_ALARM1_DAY          0x0A
    #define RTC_ALARM1_DATE         0x0A
    #define RTC_ALARM2_MINUTES      0x0B
    #define RTC_ALARM2_HOURS        0x0C
    #define RTC_ALARM2_DAY          0x0D
    #define RTC_ALARM2_DATE         0x0D
    #define RTC_CONTROL             0x0E
    #define RTC_STATUS              0x0F
    #define RTC_AGINGOFFSET         0x10
    #define RTC_TEMPERATURE_MSB     0x11
    #define RTC_TEMPERATURE_LSB     0x12
    //----------------------------------------------------
    //CENTURY BIT
    #define RTC_CENTURY             0x80
    //----------------------------------------------------
    //CONTROL BITS
    #define RTC_CTRL_A1IE           0x01
    #define RTC_CTRL_A2IE           0x02
    #define RTC_CTRL_INTCN          0x04
    #define RTC_CTRL_RS1            0x08
    #define RTC_CTRL_RS2            0x10
    #define RTC_CTRL_CONV           0x20
    #define RTC_CTRL_BBSQW          0x40
    #define RTC_CTRL_EOSC           0x80
    //----------------------------------------------------
    //STATUS BITS
    #define RTC_STATUS_A1IF         0x01
    #define RTC_STATUS_A2IF         0x02
    #define RTC_STATUS_BSY          0x04
    #define RTC_CTRL_EN32KHZ        0x08
    #define RTC_CTRL_OFS            0x80
    //----------------------------------------------------
    //ALARM 1 interval
    #define ALARM1_TICK     0b00001111     //EVERY SECOND
    #define ALARM1_MINUTE    0b00001110     //EVERY SS
    #define ALARM1_HOUR     0b00001100     //EVERY MM.SS
    #define ALARM1_DAY        0b00001000     //EVERY HH:MM.SS
    #define ALARM1_MONTH    0b00000000     //EVERY DATE:HH-MM.SS
    #define ALARM1_WEEK     0b00010000     //EVERY WEEK:HH-MM.SS
    //----------------------------------------------------
    //ALARM 2 interval
    #define ALARM2_MINUTE   0b00000111     //ONCE PER MM:00
    #define ALARM2_HOUR     0b00000110     //EVERY MM.SS
    #define ALARM2_DAY      0b00000100     //EVERY HH:MM.00
    #define ALARM2_MONTH    0b00000000     //EVERY DATE:HH-MM.00
    #define ALARM2_WEEK     0b00001000     //EVERY WEEK:HH-MM.00
    //----------------------------------------------------
    //error codes
    #define ERROR_RTC_OK            0
    #define ERROR_RTC_HOUR          1
    #define ERROR_RTC_MINUTE        2
    #define ERROR_RTC_SECOND        3
    #define ERROR_RTC_MONTH         4
    #define ERROR_RTC_DAY           5
    #define ERROR_RTC_DATE          6
    #define ERROR_RTC_YEAR          7
    #define ERROR_RTC_BCD           8
    #define ERROR_RTC_INTERVAL      9
    #define ERROR_RTC_SQUAREWAVE   10
    #define ERROR_RTC_INT          11
    #define ERROR_RTC_PIN_INUSE    12
    #define ERROR_RTC_IRQ_PIN      13
    //----------------------------------------------------
    extern int
        rtc_clrirq          (int Alarm1or2),
        rtc_daynumber       (int Date, int Month, int Year),            //dec args, return day since 1st Jan
        rtc_dumpregisters   (unsigned char Dump[19]),
        rtc_enalarm         (int Enable12),
        rtc_getirq          (),
        rtc_getday          (),                                         //Mon-Sun (1-7)
        rtc_gettemp         (),
        rtc_set12clock      (),
        rtc_set24clock      (),
        rtc_setalarm1       (unsigned long DDHHMMSS, int Interval),     //bcd
        rtc_setalarm2       (unsigned long DDHHMM,   int Interval),     //bcd
        rtc_setalarmport    (int PortB_Pin, int INT012),
        rtc_setdate         (unsigned long DDMMYYYY),                   //bcd
        rtc_setday          (int Day),                                  //Mon-Sun (1-7)
        rtc_settime         (unsigned long HHMMSS),                     //bcd
        rtc_setsquarewave   (int SquareWave),                           //0,1,1024,4096,8192,[32=32768 out on, -32=32768 out off]
        rtc_todayis         (int Date, int Month, int Year),            //dec args, return day Mon-Sun (1-7)
        rtc_validdate       (int Date, int Month, int Year),            //year 2000-2199
        rtc_validdatebcd    (unsigned long DDMMYYYY),                   //bcd
        rtc_validtime       (int Hour, int Minute, int Second),
        rtc_validtimebcd    (unsigned long HHMMSS);                     //bcd
    extern unsigned long
        rtc_getalarm1       (int *Interval),
        rtc_getalarm2       (int *Interval),
        rtc_getdate         (),                                         //DDMMYY
        rtc_gettime         ();                                         //HHMMSS
    //----------------------------------------------------
    #endif    /* DS3231RTCLIB2_H */
    //----------------------------------------------------

    ;----------------------------------------------------
    .ifndef DS3231RTCLIB2_INC
    .equiv DS3231RTCLIB2_INC,1
    ;----------------------------------------------------
    .equiv I2C_DS1307_RTC,0xd0    ;Maxim real time clock
    .equiv I2C_DS3231_RTC,0xd0    ;Maxim Extremely Accurate real time clock
    ;----------------------------------------------------
    ;registers
    .equiv RTC_SECONDS,             0x00
    .equiv RTC_MINUTES,             0x01
    .equiv RTC_HOURS,               0x02
    .equiv RTC_DAY,                 0x03
    .equiv RTC_DATE,                0x04
    .equiv RTC_CENTURY_MONTH,       0x05
    .equiv RTC_YEAR,                0x06
    .equiv RTC_ALARM1_SECONDS,      0x07
    .equiv RTC_ALARM1_MINUTES,      0x08
    .equiv RTC_ALARM1_HOURS,        0x09
    .equiv RTC_ALARM1_DAY,          0x0A
    .equiv RTC_ALARM1_DATE,         0x0A
    .equiv RTC_ALARM2_MINUTES,      0x0B
    .equiv RTC_ALARM2_HOURS,        0x0C
    .equiv RTC_ALARM2_DAY,          0x0D
    .equiv RTC_ALARM2_DATE,         0x0D
    .equiv RTC_CONTROL,             0x0E
    .equiv RTC_STATUS,        0x0F
    .equiv RTC_AGINGOFFSET,         0x10
    .equiv RTC_TEMPERATURE_MSB,    0x11
    .equiv RTC_TEMPERATURE_LSB,     0x12
    ;CENTURY BIT
    .equiv RTC_CENTURY,           7
    ;CONTROL BITS
    .equiv RTC_CTRL_A1IE,           0
    .equiv RTC_CTRL_A2IE,           1
    .equiv RTC_CTRL_INTCN,           2
    .equiv RTC_CTRL_RS1,           3
    .equiv RTC_CTRL_RS2,           4
    .equiv RTC_CTRL_CONV,           5
    .equiv RTC_CTRL_BBSQW,           6
    .equiv RTC_CTRL_EOSC,           7
    ;STATUS BITS
    .equiv RTC_STATUS_A1IF,           0
    .equiv RTC_STATUS_A2IF,           1
    .equiv RTC_STATUS_BSY,           2
    .equiv RTC_CTRL_EN32KHZ,       3
    .equiv RTC_CTRL_OFS,           8
    ;----------------------------------------------------
    ;ALARM 1 interval
    .equiv ALARM1_TICK,        0b00001111       ;EVERY SECOND
    .equiv ALARM1_MINUTE,        0b00001110     ;EVERY SS
    .equiv ALARM1_HOUR,        0b00001100     ;EVERY MM.SS
    .equiv ALARM1_DAY,        0b00001000     ;EVERY HH:MM.SS
    .equiv ALARM1_MONTH,        0b00000000     ;EVERY DATE:HH-MM.SS
    .equiv ALARM1_WEEK,        0b00010000     ;EVERY WEEK:HH-MM.SS
    ;----------------------------------------------------
    ;ALARM 2 interval
    .equiv ALARM2_MINUTE,        0b00000111     ;ONCE PER MM:00
    .equiv ALARM2_HOUR,        0b00000110     ;EVERY MM.SS
    .equiv ALARM2_DAY,        0b00000100     ;EVERY HH:MM.00
    .equiv ALARM2_MONTH,        0b00000000     ;EVERY DATE:HH-MM.00
    .equiv ALARM2_WEEK,        0b00001000     ;EVERY WEEK:HH-MM.00
    ;----------------------------------------------------
    ;error codes
    .equiv ERROR_RTC_OK,        0
    .equiv ERROR_RTC_HOUR,        1
    .equiv ERROR_RTC_MINUTE,    2
    .equiv ERROR_RTC_SECOND,    3
    .equiv ERROR_RTC_MONTH,        4
    .equiv ERROR_RTC_DAY,        5
    .equiv ERROR_RTC_DATE,        6
    .equiv ERROR_RTC_YEAR,        7
    .equiv ERROR_RTC_BCD,        8
    .equiv ERROR_RTC_INTERVAL,    9
    .equiv ERROR_RTC_SQUAREWAVE,   10
    .equiv ERROR_RTC_INT,          11
    .equiv ERROR_RTC_PIN_INUSE,    12
    .equiv ERROR_RTC_IRQ_PIN,      13
    ;----------------------------------------------------
    .endif    ;DS3231RTCLIB2_INC


    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #15
    Nikolay_Po
    Super Member
    • Total Posts : 1714
    • Reward points : 0
    • Joined: 2012/04/01 13:49:27
    • Location: Russia, Novorossiysk
    • Status: online
    Re: DS3231 and BCD time and calendar format 2018/02/07 01:54:52 (permalink)
    0
    Gort2015, The matter of taste, of course. Your code can be used for arbitrary register access. In contrast, I've created a structure to deal with whole register set in RAM at once. This allows to keep I2C read and write procedures quite simple. I've accounted that individual access to several bytes by an addresses takes comparable time to total 19 bytes at once reading/writing. The only drawback I see the 19-byte RAM is needed for DS3231 data buffering.
    #16
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 2745
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: DS3231 and BCD time and calendar format 2018/02/07 09:41:40 (permalink)
    0
    I only write the relevent sections such as time [6 bcd] that will fit into a 4byte long.
    Error checking is needed for false times and dates etc...
     
    No need to store an array of days in months such as Jan 31, March 30.
    It can be done through logic.
     

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #17
    SweetOrange
    Senior Member
    • Total Posts : 159
    • Reward points : 0
    • Joined: 2011/07/24 10:51:46
    • Location: Athens Greece
    • Status: offline
    Re: DS3231 and BCD time and calendar format 2018/02/09 02:47:07 (permalink)
    0
    Thanks for your help.
    My current code in assembler includes I2C communication with MCP9808.
    So my thought is to make a new project based on the current one,
    that would have as a main job to 'talk to' DS3231.
    That would make my effort to debug more easy.
    The device is PIC16LF18325.
     
    Alexandros
    #18
    SweetOrange
    Senior Member
    • Total Posts : 159
    • Reward points : 0
    • Joined: 2011/07/24 10:51:46
    • Location: Athens Greece
    • Status: offline
    Re: DS3231 and BCD time and calendar format 2018/02/09 04:44:57 (permalink)
    0
    Hi!
    I've made a new project dedicated for 'talking to' DS3231.
    In ds3231.asm file in i2c_rtc_initialize routine the line
    MOVLW H'D0'
        MOVWF rtc_address

     
    doesn't do what it supposed to do. rtc_address variable never gets the value of H'D0'.
    I used the Simulator to check this.
     
    I guess some better memory management is needed. I am a bit rusty on that.
    In vars.asm file I create the variable rtc_address like this:
    group6 udata
    uc_current_register_value RES 1
    uc_i2c_data RES 1
    rtc_address RES 1

     
    If you can have a look at this issue first and then I'll discuss the ds3231 routines.
     
    Any how I am attaching my code so you can have a look.
     
    vars.inc:
    ; ######################################################################
    ; Start of file "vars.inc"
    ; ######################################################################

    ; PROJECT - Temperature Meter and RTC data transmitted at 868MHz Ver.A

    ; SECTION - PCIP PIC Code

    ; MODULE

    ; ----------------------------------------------------------------------

    ; (c)2017
    ; 3 Tirynthos
    ; Peristeri
    ; Athens
    ; 12135
    ; Greece

    ; Tel. (+30) 211 4009773

    ; ======================================================================


    ; REVISION HISTORY
    ; ..........................----------------............................

    ; Mark the next block as comment by begining with #if 0 and ending with # endif.

    #if 0

    $History: vars.inc $
    ;
    ; ***************** Version 0 *****************
    ; 11-01-18 Alexandros Stefanidis
    ; Version 0 is using PIC16LF18325

    #endif

    ; ======================================================================

    ; Define external access to variables defined in vars.asm

        EXTERN bx_Temp_L, bx_Temp_W, bx_Temp_M, bx_Temp_H
        ;EXTERN Dly0, Dly1, Dly2, Dly3
        EXTERN i2cWriteData, i2cReadData, i2c_control
        ;EXTERN AddressByte, UpperByte, LowerByte, Temperature
        ;EXTERN ASCII_MSW, ASCII_LSW, BUFFER
        ;EXTERN w2, t1
        EXTERN Flags
        EXTERN uc_current_register_value, uc_i2c_data
        EXTERN rtc_address

    ; ======================================================================

     
    project.inc:
    ; ######################################################################
    ; Start of file "project.inc"
    ; ######################################################################

    ; PROJECT - Temperature Meter and RTC data transmitted at 868MHz Ver.A

    ; SECTION - PCIP PIC Code

    ; MODULE

    ; ----------------------------------------------------------------------

    ; (c)2017
    ; 3 Tirynthos
    ; Peristeri
    ; Athens
    ; 12135
    ; Greece

    ; Tel. (+30) 211 4009773

    ; ======================================================================


    ; REVISION HISTORY
    ; ..........................----------------............................

    ; Mark the next block as comment by begining with #if 0 and ending with # endif.

    #if 0

    $History: project.inc $
    ;
    ; ***************** Version 0 *****************
    ; 10-12-2017 Alexandros Stefanidis
    ; Version 0 is using PIC16LF18325

    #endif

    ; ======================================================================
    ; Listing Directives

      list P=16LF18325, r=dec, n=0, f=inhx8m, mm=ON, st=ON
      ; Default number radix is decimal
      ; f=inhx8m sets the hex file output to inhx8m
      ; mm=ON prints the memory map in the list file
      ; st=ON prints the symbol table in the list file

      errorlevel 0 ; Print all messages, warnings and errors in the list file
    ; errorlevel -302 ; Suppress "Msg 302: Register not in bank 0. Ensure bank bits are correct."
      
      title "TemperatureRTC Meter Ver.A(16LF218325)"
      subtitle "(c)Alexandros Stefanidis"
     
      ;Macro Directives
      
      expand ; Print macro expansions in the list file

    ; Included files

    #include <P16LF18325.INC>
    ;#include "macros.inc"
    ;===============================================================================
    ; Status Bits

    #define SR_NPD STATUS,NOT_PD ; Power-Down bit
    #define SR_NTO STATUS,NOT_TO ; Time-Out bit
    #define SR_Zero STATUS,Z
    #define SR_DC STATUS,DC
    #define SR_Carry STATUS,C

    #19
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re: DS3231 and BCD time and calendar format 2018/02/09 04:51:16 (permalink)
    0
    Probably a banking error.
    What bank is "rtc_address" in?
    What bank is active when you write to it?
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2018 APG vNext Commercial Version 4.5