• AVR Freaks
Reply to post

Hot!MCP79520 - issue setting date to the 31st of the month

Author
otisman37
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2019/10/31 17:08:01
  • Location: 0
  • Status: offline
2019/11/05 15:00:26 (permalink)
0

MCP79520 - issue setting date to the 31st of the month

Hello forum, this is my first post.  I've come across a strange problem that I cannot solve.  We use the MCP79520 RTCC in a product we recently released.  On the 31st of October we had a few calls where customers could not set the date correctly.  When setting the date to the 31st of October, it would revert to the 1st of October.  The data being written to the chip seems to be correct, and setting to (most) any other date works.
ie. Setting the date to 31st of January works, and 31st of March works.  The issue only occurs for 31st of May, July, August, October and December.  Also 29th of February on a leap year does not work.
The clock will roll from the 30th to 31st without issue - but we just can't set the date to the 31st, it always come back as the 1st.  Does anyone have any ideas?!

10 Replies Related Threads

    ric
    Super Member
    • Total Posts : 24639
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: MCP79520 - issue setting date to the 31st of the month 2019/11/07 21:41:17 (permalink)
    0
    How are you writing the new date?
    Are you doing all the registers in a single transfer, or one register per transfer?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    NKurzman
    A Guy on the Net
    • Total Posts : 18061
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: MCP79520 - issue setting date to the 31st of the month 2019/11/07 21:56:54 (permalink)
    0
    What number are you using for October?
    Is January 0 or 1 on you chip?
    NKurzman
    A Guy on the Net
    • Total Posts : 18061
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: MCP79520 - issue setting date to the 31st of the month 2019/11/07 22:08:12 (permalink)
    0
    Duplicate
    ric
    Super Member
    • Total Posts : 24639
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: MCP79520 - issue setting date to the 31st of the month 2019/11/07 22:09:43 (permalink)
    0
    According to TABLE 5-3: in the datasheet, January is 01.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    ric
    Super Member
    • Total Posts : 24639
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: MCP79520 - issue setting date to the 31st of the month 2019/11/11 12:28:11 (permalink)
    0
    Any news otisman37?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    otisman37
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2019/10/31 17:08:01
    • Location: 0
    • Status: offline
    Re: MCP79520 - issue setting date to the 31st of the month 2019/11/11 20:46:48 (permalink)
    0
    Hi, Thanks for the replies, and sorry for my late response.
     
    I have not been able to work it out yet.  The behavior is very odd.  A few days ago, setting the 30th of November worked no problem, but today it did not work (reverting to the 1st)... until I set the time to 23:59 on the 29th of November, and let it roll over by itself to the 30th.... now I can set the 30th of November no problem...
     
    @ric we send everything in one transfer, so the day of the month is somewhere in the middle.
     
    @NKurzman, January is 01 - October is 10.  BCD format.
     
    ric
    Super Member
    • Total Posts : 24639
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: MCP79520 - issue setting date to the 31st of the month 2019/11/11 20:53:27 (permalink)
    0
    What if you set it twice?
    That would ensure it had the correct month selected when the date was written in the second transfer.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    otisman37
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2019/10/31 17:08:01
    • Location: 0
    • Status: offline
    Re: MCP79520 - issue setting date to the 31st of the month 2019/11/11 20:55:14 (permalink)
    0
    This is the function that writes to the RTCC, called in the main loop of the program.
    It will write to the RTCC when "writertccreq" is true.
     
    int writeXRTCCseq(void) {
    auto unsigned char rd_data, wr_data;
    auto unsigned char secs;
    switch (WXState) {
    case 0:
    if (spimode == 1) {
    if (writertccreq && (RXState == 0)) {
    WXState = 1;
    writertccreq = 0;
    }
    }
    break;
    case 1:
    rtcc_st = 1;
    rtcc_24 = 0;
    rtcc_vbaten = 1;
    rtcc_control = 0x40; // SQWE = 1
    CSRTCC = 0; // select the external RTCC
    SPI2BUFL = RTCC_READ; // send read command
    WXState++;
    break;
    case 2:
    if (SPI2STATLbits.SPIRBF) { // SPI transfer complete?
    rd_data = SPI2BUFL; // ignore this data
    SPI2BUFL = 0x01; // RTCC/SRAM address 0x01
    WXState++;
    }
    break;
    case 3:
    if (SPI2STATLbits.SPIRBF) { // SPI transfer complete?
    rd_data = SPI2BUFL; // ignore this data
    SPI2BUFL = 0; // send dummy, read data at address 0x01
    WXState++;
    }
    break;
    case 4:
    if (SPI2STATLbits.SPIRBF) { // SPI transfer complete?
    rd_data = SPI2BUFL;
    CSRTCC = 1; // de-select external RTCC
    secs = rd_data & 0x7F;
    if (secs == 0x59) { // wait if in 59th second
    WXState = 1;
    } else {
    WXState++;
    }
    }
    break;
    case 5:
    CSRTCC = 0; // select the external RTCC
    SPI2BUFL = RTCC_WRITE; // send write command
    WXState++;
    break;
    case 6:
    if (SPI2STATLbits.SPIRBF) { // SPI transfer complete?
    rd_data = SPI2BUFL; // ignore this data
    SPI2BUFL = 0x01; // send RTCC/SRAM address 0x01
    WXState++;
    }
    break;
    case 7:
    if (SPI2STATLbits.SPIRBF) { // SPI transfer complete?
    rd_data = SPI2BUFL; // ignore this data
    wr_data = set_tm.sec ;
    wr_data |= (rtcc_st << 7);
    SPI2BUFL = wr_data; // send data for address 0x01
    WXState++;
    }
    break;
    case 8:
    if (SPI2STATLbits.SPIRBF) { // SPI transfer complete?
    rd_data = SPI2BUFL; // ignore this data
    wr_data = set_tm.min;
    SPI2BUFL = wr_data; // send data for address 0x02
    WXState++;
    }
    break;
    case 9:
    if (SPI2STATLbits.SPIRBF) { // SPI transfer complete?
    rd_data = SPI2BUFL; // ignnore this data
    wr_data = set_tm.hour;
    wr_data |= (rtcc_calsgn << 7);
    wr_data |= (rtcc_24 << 6);
    SPI2BUFL = wr_data; // send data for address 0x03
    WXState++;
    }
    break;
    case 10:
    if (SPI2STATLbits.SPIRBF) { // SPI transfer complete?
    rd_data = SPI2BUFL; // ignore this data
    wr_data = set_dt.wday;
    wr_data |= (rtcc_vbat <<4);
    wr_data |= (rtcc_vbaten << 3);
    SPI2BUFL = wr_data; // send data for address 0x04
    WXState++;
    }
    break;
    case 11:
    if (SPI2STATLbits.SPIRBF) { // SPI transfer complete?
    rd_data = SPI2BUFL; // ignore this data
    wr_data = set_dt.mday;
    SPI2BUFL = wr_data; // send data for address 0x05
    WXState++;
    }
    break;
    case 12:
    if (SPI2STATLbits.SPIRBF) { // SPI transfer complete?
    rd_data = SPI2BUFL; // ignore this data
    wr_data = set_dt.mon;
    wr_data |= (rtcc_lp << 5);
    SPI2BUFL = wr_data; // send data for address 0x06
    WXState++;
    }
    break;
    case 13:
    if (SPI2STATLbits.SPIRBF) { // SPI transfer complete?
    rd_data = SPI2BUFL; // ignnore this data
    wr_data = set_dt.year;
    SPI2BUFL = wr_data; // send data for address 0x07
    WXState++;
    }
    break;
    case 14:
    if (SPI2STATLbits.SPIRBF) { // SPI transfer complete?
    rd_data = SPI2BUFL; // ignnore this data
    wr_data = rtcc_control;
    SPI2BUFL = wr_data; // send data for address 0x08
    WXState++;
    }
    break;
    case 15:
    if (SPI2STATLbits.SPIRBF) { // SPI transfer complete?
    rd_data = SPI2BUFL; // ignnore this data
    wr_data = rtcc_calibration;
    SPI2BUFL = wr_data; // send data for address 0x09
    WXState++;
    }
    break;
    case 16:
    if (SPI2STATLbits.SPIRBF) { // SPI transfer complete?
    rd_data = SPI2BUFL; // ignore this data
    CSRTCC = 1; // de-select external RTCC
    WXState = 0;
    }
    break;
    default:
    WXState = 0;
    }
    return WXState;
    }
    otisman37
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2019/10/31 17:08:01
    • Location: 0
    • Status: offline
    Re: MCP79520 - issue setting date to the 31st of the month 2019/11/11 20:59:05 (permalink)
    0
    // FUNCTION DECLARATIONS
    // union/structure for read/write of time into the RTCC device
    typedef union
    {
    struct
    {
    BYTE rsvd; // reserved for future use
    BYTE sec; // BCD codification for seconds, 00-59
    BYTE min; // BCD codification for minutes, 00-59
    BYTE hour; // BCD codification for hours, 00-24
    }; // field access //this was anonymous in xc32...
    BYTE b[4]; // BYTE access
    unsigned short int w[2]; // 16 bits access
    unsigned long int l; // 32 bits access
    }rtccTime;

    // union/structure for read/write of date into the RTCC device
    typedef union
    {
    struct
    {
    BYTE wday; // BCD codification for day of the week, 00-06
    BYTE mday; // BCD codification for day of the month, 01-31
    BYTE mon; // BCD codification for month, 01-12
    BYTE year; // BCD codification for years, 00-99
    }; // field access
    BYTE b[4]; // BYTE access
    unsigned short int w[2]; // 16 bits access
    unsigned long int l; // 32 bits access
    }rtccDate;
    otisman37
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2019/10/31 17:08:01
    • Location: 0
    • Status: offline
    Re: MCP79520 - issue setting date to the 31st of the month 2019/11/11 21:05:15 (permalink)
    0
    @ric, It doesn't work if you set it twice...  I tried that!   
     
    Earlier in development there was a bug where the month could be set to zero - and it accepted that.  I can't remember the exact behaviour, but I think it automatically fixed itself (to January) when it rolled over to the next day.
     
    Guest
    Quick Reply: (Open Full Version)
      Enter the random characters shown
    Submit Post
    Some restrictions apply to prevent link (URL) Spam.
    URLs in messages, signatures, and PM's are removed unless you have ...
    • been a member for at least 0 day(s);
    • made a total of 0 post(s);
    • earned at least 0 point(s) for post scores (based on the ratings on your posts);
    • earned at least 0 reward point(s);
    Jump to:
    © 2019 APG vNext Commercial Version 4.5