DS1307 real time clock

Posted on
  • can any body give me the sample code for DS1307??

  • There's the module for the DS3231 RTC at http://www.espruino.com/DS3231 that might be very similar?

    But do you know that Espruino already has an RTC built-in? It may be you don't actually need the DS1307...

  • ya i knw that but i have to make use of NVRAM.
    thanks for your reply...!!

  • Maybe move this to Interfacing? :)

  • No problem!

    I don't know if this is helpful, but Espruino has NVRAM too. You can use the following functions (at least on the original Espruino board) to access it:

    function nvaddr(n) {
      if (n>=0 && n<10) return 0x40006C04+n*4;
      if (n>=10 && n<42) return 0x40006C40+(n-10)*4;
      return 0;
    }
    
    // 16 bits, a=0..41
    function nvread16(a) {
      return peek16(nvaddr(a));
    }
    
    // 16 bits, a=0..41
    function nvwrite16(a, value) {
      return poke16(nvaddr(a), value);
    }
    

    For instance:

    for (var i=0;i<42;i++) nvwrite16(i, i*100)
    
    // then do a hard reset
    
    for (var i=0;i<42;i++) console.log(nvread16(i))
    0
    100
    200
    300
    ...
    4000
    4100
    

    Obviously you still need a battery to be connected to the board for that though.

    (and yes, moving the topic now)

  • DS1307 interface looks considerably different in terms of control, compared to 3231.

    If all you need is the non-volatile memory, couldn't you use an EEPROM, like something from the AT24 series? That'd get you way more capacity, at around the same price point. 2 of my 3 Espruino boards have an AT24 in SOIC package sitting in the proto area (it also comes in DIP)

    Also, wait, the Espruino has 42 2-byte words worth of non-volatile memory?! That would have been really nice to know on a few occasions - that's really handy. Does the 401 in the pico have that too? (Would it be hard to put in E.NVWrite()/NVRead() or something like that? That would be a really good functionality to expose, since people coming from Arduino are used to having some built-in EEPROM.

  • Also, wait, the Espruino has 42 2-byte words worth of non-volatile memory?!

    Yep - sorry, I only really noticed it when fiddling with the RTC. It's on the Pico as well (albeit as 20 x 32 bit values at a different address).

    ... should probably talk about this in a new topic - but yes, it could be added to Espruino - it seems like the kind of thing that'd be fine as a module though.

  • Is it something that the configuration for can go into board.py files? It'd be a worthy addition to save people from trawling datasheets for the addresses for their particular board.

    lines starting with a 'greater than' denote quoted text

  • Well, a module could just check process.env and then use the correct addresses...

    If implemented internally it's probably something that should go into jshardware.c as it basically only varies by chip family (F1/F4/etc) rather than the board.

  • yes i can..
    but how many times can i do the read and write operations to the AT24 series EEPROM?

  • yes it will help full to me.
    but,
    I tried this but the result was all zeros

  • I tried this but the result was all zeros

    Are you using the Espruino Board with an up to date firmware, or are you using a different type of board?

  • internal #NVRAM

    ...nice to know, just right for saving some ID / basic config / state information.

  • Iam using STM32F103VCT6 espruino board,
    with espruino_1v77.
    still the result was all zeros.
    Thanks for reply....!!!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

DS1307 real time clock

Posted by Avatar for krishna @krishna

Actions