Hello,
UEXT module MOD-RTC (there is a battery) is not working with PIC32-PINGUINO-MICRO, I download the program "MOD-RTC example" loaded to board but, every time the same massage:
Time & Date:
0:0:0
D/M/Y: 0.0.0
Day of the week: Sunday
Change the declaration from:flag = set_time_date(0,0,0,0,1,1,0);
to: flag = set_time_date(0,34,10,3,1,12,12);
But not, same.. 000
It is look like the Clock it Ticking :), Any ideas Why?
I modify the program from "regis blanchot" he give it to me, and I find it very useful:
/* ---------------------------------------------------------------------------
FILE: pcf8563_RTC.pde
PROJECT: pinguino
PURPOSE: Setting and reading PFC8563 RTC via i2c
PROGRAMER: regis blanchot <rblanchot@gmail.com>
FIRST RELEASE: 29 May 2102
LAST RELEASE: 29 May 2102
---------------------------------------------------------------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
---------------------------------------------------------------------------
The PFC8563 RTC is connected to the board via the Olimex UEXT connector
so no circuit diagram
--------------------------------------------------------------------------*/
//PCF8574 PCF8574_data; // PCF8574's registers
//u8 PCF8574_address; // PCF8574's I2C address
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);
}
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");
}
}
My version for RTC with display is:
/*-----------------------------------------------------
Author: --<Stanislav Vasilev>
stnani@abv.bg
Date: 11/Dec/2012
Description:
Real time clock buil by pcf8563_RTC it is connected to the board via the Olimex UEXT connector
so no circuit diagram.
LCD display 4x16 conected to pins
-----------------------------------------------------*/
//Real Time clock parameters
#define PFC8563_write_add 0xA2
#define PFC8563_read_add 0xA3
unsigned char secs;
unsigned char mins;
unsigned char hour;
unsigned char day;
unsigned char wday;
unsigned char month;
long year;
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"};
long lastTime = 0; // temporary time value
long Delay = 100; // delay time
void setup()
{
I2C.init(); // I2C_MASTER_MODE, I2C_SLEW_OFF
lcd.pins(12, 11, 3, 2, 1, 0, 0, 0, 0, 0); // 4 bits mode of LCD display
lcd.begin(16,2,0);// set up the LCD's number of columns and rows:
}
//
void loop()
{
if ((millis() - lastTime) > Delay) // Pause between readings
{
lastTime = millis();
//i2c communication sequences
I2C.start();
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))); // read bits from registers and convert them to binar format
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();
// Display time parameters on lcd
lcd.setCursor(0, 0);
lcd.printf("%02d:%02d:%02d %3s", hour, mins, secs, Day[wday]); // first (upper) line
lcd.setCursor(0, 1);
lcd.printf("%02d-%03s-%04d", day, Month[month], year); // second line
}
}
Every thing is working now
Well, on the pinguino.cc forum it is said that the PIC32-PINGUINO-MICRO indeed HAS a built-in RTC,
but you need to solder on a 32 kHz crystal and 2 capacitors.