Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding an RTC to MICRO
13-01-2013, 05:13 PM,
#1
Adding an RTC to MICRO
If I add an external RTC circuit to Pinguino MICRO, can I connect it in such a way it is compatible with Pinguino RTCC library?
I have a Sparkfun DS1307-based breakout:
https://www.sparkfun.com/products/99

it has pins SDA, SCL, SQW, GND and 5V.
Datasheet: http://www.sparkfun.com/datasheets/Compo...DS1307.pdf
Reply
13-01-2013, 07:48 PM,
#2
RE: Adding an RTC to MICRO
Isn't it completely different hardware, completely incompatible with the existing software, so wouldn't you of course need to rewrite the software?

John
Reply
14-01-2013, 07:53 AM, (This post was last modified: 14-01-2013, 07:53 AM by moreno.)
#3
RE: Adding an RTC to MICRO
Hi

Why a module so expensive?? at this point is more cheaper buy the PINGUINO32-OTG

Olimex sells this RTC module for UEXT port, with sample code for Pinguino IDE.


Bye Bye, Moreno
Reply
16-01-2013, 03:50 PM,
#4
RE: Adding an RTC to MICRO
Just to add to PINOTG post (Post: #2 above) the existing X.3 RTCC library is written around the functionality built into the MicroChip PIC32MX440F256H. The various completely external modules available, such as the Sparkfun DS1307 and the Olimex UEXT module are connected via an I2C interface and do not use the PIC32MX440F256H functionality which is why they are not compatible with the existing RTCC library.

Comparing the Olimex schematics for the PIC32 OTG and the PIC32 Micro it seems that the PIC32 Micro is missing the RTCC crystal (Q2) and associated capacitors (C9 & C10) and it might be possible to add these externally provided that the strays associated with the board layout and external pinouts etc do not present too many problems. Whether this would be viable also depends on whether there is anything else in the Pinguino environment that would stop the PIC32 Micro addressing the RTCC functionality.

I am not familiar with the DS1307 used by the Sparkfun module but have experimented with the PFC8563 RTC used by the Olimex MOD-RTC UEXT module which can be plugged directly into the UEXT connector on the PIC32 Micro. If you would like some hints on using this module I can post the code I used to set and read the module via I2C. Let me know and also which version of the IDE you are using (X? and r?) and I will see if I can check it still works (there have been some revisions to the IDE since I last tried it).

Regards
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
16-01-2013, 06:18 PM,
#5
RE: Adding an RTC to MICRO
Yes, Micro is declared as not having RTC, nor having any additional lofreq crystal, nor having any chance to support adding an RTC just by connecting a crystal and some capacitors.
BUT being DS1307 I2C driven, I think it's compatible with any I2C-supporting device: it is self contained and does not require even power having builtin battery.
Your old sources would be much appreciated thanks.
Reply
16-01-2013, 08:04 PM,
#6
RE: Adding an RTC to MICRO
Hi jumpjack,

I am not sure I would agree 100% with your comment about the PIC32 Micro not having any chance to support adding an RTC just by connecting a crystal and some capacitors. The same pins on the PIC32MX440F256H (47 & 48) that are internally connected to the RTC crystal and capacitors on the PIC32 OTG are brought out to external connectors (CON1-1 & CON1-2) on the PIC32 Micro so it may be possible to add them externally but the stray capacitances etc it is not guaranteed that this will work.

The advantage of using either the Sparkfun DS1307 and the Olimex MOD-RTC UEXT is that they both can use a backup battery and hence maintain their timekeeping even when power is removed from the Pinguino.

Below is my code for use with the Olimex MOD-RTC UEXT. The code is specific to the PFC8563 used on the Olimex module. Looking at the last date I modified the file it might be dependent on some changes made in a later revision of X.3. If you can give me a clue as to the revision of X.3 you are running (e.g. did you download and run a complete installation or "checkout" a copy using using subversion and if so when?)

The code within the setup loop which sets the RTC has been remarked out as this code is only run once when initially setting the PFC8563. The code as written sets the RTC to start at 21:00:00 Sun 11 Nov 2012.

Initially when trying to use some other i2c devices with the Pinguino I had some difficulty understanding how the i2c address needed to be expressed. In my example (and the Pinguino i2c libraries) it is assumed that the address is written as an 8 bit value including the read/write bit. Therefore if you are use the DS1307 the write address will be 0xD0 and the read address will be 0xD1. See the Pinguino wiki for further details of I2C Addresses. From a brief look at the DS1307 datasheet there will be considerable other changes needed to get the code to work with that device.

If I remember correctly when first attempting to read data from the PFC8563 I got some anomalous answers until I initialised it correctly. I do not know whether the DS1307 is the same but it is something to look out for.

Code:
/*    ---------------------------------------------------------------------------
   FILE:       pcf8563_RTC.pde
   PROJECT:    pinguino
   PURPOSE:    Setting and reading PFC8563 RTC via i2c
   ---------------------------------------------------------------------------
   The PFC8563 RTC is connected to the board via the Olimex UEXT connector
   so no circuit diagram
   --------------------------------------------------------------------------*/

const u8 PFC8563_write_add = 0xA2;
const u8 PFC8563_read_add  = 0xA3;

char    Day[7][4]      = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
char    Month[13][4]   = {"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};

void setup()
{
   /* Set up the register word address (0x00, the first register) and the values for
      all 16 registers as summarised in Table 4,. Formatted registers overview, in the
      PFC8563 Real-time clock/calendar Product Data Sheet Rev.9 16 June 2011
      
      Note: To ensure integrity of clock settings all time and date settings should
            be done in a single write                                              
   */

/*  
   CDC.printf("The set up loop started \r\n");

   u8 PFC8563_settings[17] = {0x00, // word address 0, next bytes are data
                              0x00, // 00 control/status 1, no test modes or POR override
                              0x00, // 01 Control/status 2, no alarm/timer flags or interrupts
                              0x00, // 02 set seconds, clear low voltage detector
                              0x00, // 03 set minutes
                              0x21, // 04 set hours
                              0x11, // 05 set days
                              0x00, // 06 set weekdays, Sunday is 0, Monday is day 1 etc
                              0x11, // 07 set month and century
                              0x12, // 08 set years
                              0x80, // 09 disable minute alarm and reset to 00
                              0x80, // 0A disable hour alarm and reset to 00
                              0x80, // 0B disable day alarm and reset to 00
                              0x80, // 0C disable weekday alarm and reset to 00
                              0x80, // 0D set frequency out to 32768 Hz e.g. for tuning
                              0x00, // 0E timer switched off
                              0x01};// 0F timer value register set to 1
   u8 i;
   delay(500);  // Wait 1/2 second to make sure that oscillator has had time to start
   I2C.init();        // I2C_MASTER_MODE, I2C_SLEW_OFF
   I2C.start();
   I2C.writechar(PFC8563_write_add);
   for (i=0; i<17; i++){
      I2C.writechar(PFC8563_settings[i]);
   }
   I2C.stop();

   CDC.printf("The set up loop completed \r\n");
*/  
}

void loop()
{
   u8 i;
   u8 time_data[10];
   u8 secs, mins, hour, day, wday, month;
   u16   year;
  
   delay(5000);
  
   /* Read clock date and time - to ensure integrity of clock settings all
      time and date data should gathered in a single read.                                              
   */

   I2C.init();        // I2C_MASTER_MODE, I2C_SLEW_OFF
   I2C.start();
   if (I2C.writechar(PFC8563_write_add)){
      I2C.writechar(0x02); // RTC data starts at word/register 02
      I2C.restart();
      I2C.writechar(PFC8563_read_add);
      secs  = bcd2bin(0x7F & (I2C_readchar(I2C1, false)));
      mins  = bcd2bin(0x7F & (I2C_readchar(I2C1, false)));
      hour  = bcd2bin(0x3F & (I2C_readchar(I2C1, false)));
      day   = bcd2bin(0x3F & (I2C_readchar(I2C1, false)));
      wday  = bcd2bin(0x07 & (I2C_readchar(I2C1, false)));
      month = bcd2bin(0x1F & (I2C_readchar(I2C1, false)));
      year  = 2000 + (bcd2bin(0x3F & I2C.readchar()));
      I2C.stop();
      CDC.printf("%02d:%02d:%02d %3s %02d-%03s-%04d \r\n", hour, mins, secs, Day[wday], day, Month[month], year);
      }
   else{
      I2C.stop();
      CDC.printf("No response \r\n");
      }

}

Regards
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
16-01-2013, 11:30 PM,
#7
RE: Adding an RTC to MICRO
Thanks.
I also found this page, I'll attempt a merge. :-)
http://www.ladyada.net/learn/breakoutplu...07rtc.html
Reply
17-01-2013, 05:00 PM,
#8
RE: Adding an RTC to MICRO
Hi jumpjack,

I found another example of using the Olimex MOD-RTC UEXT module with PFC8563 on the Olimex website (https://www.olimex.com/Products/Modules/Time/MOD-RTC/) under the heading "Software" towards the bottom of the page. According to the "PIGUINO_MODRTC_Readme.txt" file in the zip file "This project compiles and works with Pinguino X3 rev.399 Windows" so it may be a better starting point if that is the version of Pinguino X3 that you are using. As far as I am aware rev.399 is the last full installer version of Pinguino X3 IDE available from code.google.com/p/pinguino web site.

Looking at the program (.pde) file in the source folder in the zip file this program does not appear to use the Pinguino I2C library which I seem to remember had some changes after rev.399 so if you run into problems with I2C this may be an alternative. You will still need to change it to work with the DS1307 rather than the PFC8563 as used by the Olimex MOD-RTC UEXT. Partly due to not using the Pinguino I2C library and partly due to having greater functionality the Olimex example is considerably more complex than the one I include in Post: #6 above.

Regards
Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
Reply
29-05-2013, 02:44 PM,
#9
RE: Adding an RTC to MICRO
Quote:Posted by mf01 - 16-01-2013 08:04 PM
Hi jumpjack,

I am not sure I would agree 100% with your comment about the PIC32 Micro not having any chance to support adding an RTC just by connecting a crystal and some capacitors. The same pins on the PIC32MX440F256H (47 & 48) that are internally connected to the RTC crystal and capacitors on the PIC32 OTG are brought out to external connectors (CON1-1 & CON1-2) on the PIC32 Micro so it may be possible to add them externally but the stray capacitances etc it is not guaranteed that this will work.

I just need an RTC on my PIC32-MICRO and in the next day I'll test IF installing xtal + 2 caps would be enough....
Maybe that stray capacitance doesn't permit regular oscillation, but in this case building [or getting a block-sized] an EXTERNAL OSCILLATOR and feeding the signal to pin SOSCI [conn 1-2] probably does work...
I'll report my results soon [I hope Wink]
Reply
07-06-2013, 02:02 PM,
#10
RE: Adding an RTC to MICRO
Quote:I'll report my results soon [I hope Wink]
Here I'm: connecting a standard Xtal + 2 caps [tried different caps value and different xtal] on the board sometimes the OSC starts but it's completely unaffordable... Looking at several Application Notes seems that the layout is A LOT critical....
Tested too a "block" oscillator, this works... but, to retain the time&date we are constrained to "power backup" all the board.
So I think that a DS1307 it's a better choice.... the pin count it's the same (2 pin dedicated to RTC SCL/SCK or OSCI/OSCO) but with a simple CR2032 battery we've about 10 years of backup.

These are my two [euro]cent...

Ciao ciao Wink
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)