Shop OBEX P1 Docs P2 Docs Learn Events
Real Time Clock — Parallax Forums

Real Time Clock

DiscoveryDiscovery Posts: 606
edited 2014-08-18 18:24 in Propeller 1
I use a Dallas Semiconductor DS1302 real time clock with BS2 series controllers. I would like to migrate the software and the clock to a Propeller.

Can that be accomplished? If so, how?

Sincerely,

Discovery

Comments

  • TtailspinTtailspin Posts: 1,326
    edited 2014-08-10 20:02
    It can be done. :smile:
    Try looking through this code from the OBEX. DS1302 full



    -Tommy
  • DiscoveryDiscovery Posts: 606
    edited 2014-08-10 21:33
    Shall do...thanks.

    Discovery
  • Heater.Heater. Posts: 21,230
    edited 2014-08-11 03:24
    Anyone like to recommend an RTC for a Prop proto board that has a empty SOIC pad pattern waiting for it?
  • DiscoveryDiscovery Posts: 606
    edited 2014-08-11 05:15
    Is a C code solution available to operate a DS1302 with the Propeller?

    Discovery
  • cavelambcavelamb Posts: 720
    edited 2014-08-11 07:24
    Heater. wrote: »
    anyone like to recommend an rtc for a prop proto board that has a empty soic pad pattern waiting for it?

    ds1337
  • PropGuy2PropGuy2 Posts: 360
    edited 2014-08-11 07:46
    For a RTC i recommend a DS3234 ic. It has a ton of features: easy SPI interface, built-in temperature compensated crystal, very accurate, extra SRAM built in, alarm features, easy battery backup, the list goes on. Down side, it is a little pricey at $8, but worth every penny IMHO.
  • jazzedjazzed Posts: 11,803
    edited 2014-08-11 12:33
    Heater. wrote: »
    Anyone like to recommend an RTC for a Prop proto board that has a empty SOIC pad pattern waiting for it?


    Any of the DS13xx chips will work. Some have more pins than others of course and different features.

    I've used this one: http://www.mouser.com/ProductDetail/Maxim-Integrated/DS1338Z-33+/?qs=0Y9aZN%252bMVCVblIXsYVg1wg==

    Below is code that will integrate into the standard C time functions in PropellerGCC.

    The GbI2C_rtc_getReg() and GbI2C_rtc_writeReg() functions to access the RTC hardware are left as an exercise for the user.

    /*
    =================================================================
    RTC REGISTERS
    =================================================================
    */
    
    
    #define GbI2C_RTC_SECOND    0
    #define GbI2C_RTC_MINUTE    1
    #define GbI2C_RTC_HOUR      2
    #define GbI2C_RTC_DAY       3
    #define GbI2C_RTC_DATE      4
    #define GbI2C_RTC_MONTH     5
    #define GbI2C_RTC_YEAR      6
    #define GbI2C_RTC_CONTROL   7
    
    
    int RTC_getTime(struct timeval *tv)
    {
        struct tm t;
        
        /* read all rtc registers */
        GbI2C_rtc_readRegs();
        
        /* get rtc register fields */
        t.tm_sec  = GbI2C_rtc_getReg(GbI2C_RTC_SECOND);
        t.tm_min  = GbI2C_rtc_getReg(GbI2C_RTC_MINUTE);
        t.tm_hour = GbI2C_rtc_getReg(GbI2C_RTC_HOUR);
        t.tm_wday = GbI2C_rtc_getReg(GbI2C_RTC_DAY);
        t.tm_mday = GbI2C_rtc_getReg(GbI2C_RTC_DATE);
        t.tm_mon  = GbI2C_rtc_getReg(GbI2C_RTC_MONTH)-1;
        t.tm_year = GbI2C_rtc_getReg(GbI2C_RTC_YEAR)+YEARADJUST;
    
    
        mytime = mktime(&t);
        
        tv->tv_sec = mytime;
        tv->tv_usec = 0;
        
        //printf("t %02d:%02d:%02d ",t.tm_hour, t.tm_min, t.tm_sec);
        //printf(" %02d-%02d-%04d %d ",t.tm_mon, t.tm_mday, t.tm_year, t.tm_wday);
        printf("RTC_getTime %d sec. TimeStamp %s\n", mytime, asctime(&t));
    
    
        return 0;
    }
    
    
    int RTC_setTime(const struct timeval *tv)
    {
        struct tm *t;
        //mytime = tv->tv_sec*1000;
        t = localtime(tv->tv_sec*1000);
            
        /* write rtc register fields */
        GbI2C_rtc_writeReg(GbI2C_RTC_SECOND, t->tm_sec);
        GbI2C_rtc_writeReg(GbI2C_RTC_MINUTE, t->tm_min);
        GbI2C_rtc_writeReg(GbI2C_RTC_HOUR, t->tm_hour);
        GbI2C_rtc_writeReg(GbI2C_RTC_DAY, t->tm_wday);
        GbI2C_rtc_writeReg(GbI2C_RTC_DATE, t->tm_mday);
        GbI2C_rtc_writeReg(GbI2C_RTC_MONTH, t->tm_mon+1);
        GbI2C_rtc_writeReg(GbI2C_RTC_YEAR, t->tm_year-YEARADJUST);
    
    
        //printf("t %02d:%02d:%02d ",t->tm_hour, t->tm_min, t->tm_sec);
        //printf(" %02d-%02d-%04d %d ",t->tm_mon, t->tm_mday, t->tm_year, t->tm_wday);
        printf("RTC_setTime %d sec. TimeStamp %s\n", mytime, ctime(t));
        RTC_getTime(tv);
        return 0;
    }
    
    
    void RTC_init()
    {
        _rtc_gettime = RTC_getTime;
        _rtc_settime = RTC_setTime;
    }
    
    
    
  • DiscoveryDiscovery Posts: 606
    edited 2014-08-18 14:31
    Hi Jazzed,

    I cannot get this code to compile...should it as supplied?

    Discovery
  • Mark_TMark_T Posts: 1,981
    edited 2014-08-18 14:44
    The DS1338-33 is the 3.3V equivalent of the standard DS1307, pin and software compatible.
  • jazzedjazzed Posts: 11,803
    edited 2014-08-18 15:01
    Discovery wrote: »
    Hi Jazzed,

    I cannot get this code to compile...should it as supplied?

    Discovery


    No. It is a snippet. I've given instructions on what needs to be done.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-08-18 15:16
    Heater. wrote: »
    Anyone like to recommend an RTC for a Prop proto board that has a empty SOIC pad pattern waiting for it?

    Never bother with SPI RTCs, there's no point unless it's price sensitive in volume. The I2C versions connect straight to P28,P29 I2C pins so you don't waste any I/O. At present I am using MCP79410 as RTCs as the 411/412 are also available with unique MAC addresses. The chip also includes a timing correction register. Other than that they also include EEPROM which is good for configuration data and some RAM as well. Even in one off they are only a buck a piece or double that from Element14.
  • DiscoveryDiscovery Posts: 606
    edited 2014-08-18 18:21
    Jazzed,

    I am sure that your comment was well intended; however, I am struggling to get C programs to work using the IDE. The only method that I found that works is to obtain a C program from forum personnel that works then I make changes until the program does what I want it to do. For me to write C programs from the definitions of functions just isn't happening.

    Sincerely,

    Discovery
  • DiscoveryDiscovery Posts: 606
    edited 2014-08-18 18:24
    Peter,

    Do you have code that works with the MCP79410 RTC that you would send to me? In the mean time I will checkout the RTC at Element14.

    Thanks,

    Discovery
Sign In or Register to comment.