2
\$\begingroup\$

I'm trying to get the internal RTCC working but it doesn't seem to work.

What I'm using-

  • MikroC pro for PIC
  • using internal 8mhz clock(INTOSCPLL)
  • Using INTRC as a clock source for RTCC

and using the following code:

 void main() {

 char txt[7];

 //Setup RTC
 T1CON.T1OSCEN = 1;
 delay_ms(50);
 RTCCFG.RTCWREN = 1;
 PADCFG1.RTSECSEL1 = 1;
 PADCFG1.RTSECSEL0 = 0;
 RTCCFG.RTCEN = 1;
 RTCCFG.RTCPTR1 = 0;
 RTCCFG.RTCPTR0 = 0;

 //Set analog ports as Digital
 ANCON0 = 0x1F;
 ANCON1 = 0x1F;

 I2C1_Init(400000);
 Oled_Init();
 Oled_FillScreen(0x00);

 while(1){
    IntToStr(RTCVALH, txt);
    Oled_Text(txt,0,2);
    IntToStr(RTCVALL, txt);
    Oled_Text(txt,0,4);
    delay_mS(1000);
 }
}

The RTCVALH and RTCVALL should display minutes and seconds. But their values don't change at all. They show constant values of 56 and 50.

What steps am I missing?

\$\endgroup\$
1
\$\begingroup\$

I believe you need to set RTCCFG.RTCWREN = 0; after you have finished writing to it. The datasheet mentions it under section 17.2.7 WRITE LOCK

\$\endgroup\$
0
\$\begingroup\$

Make sure your configuration bits for setting the RTC clocking source are correct. The bits responsible for is the RTCOSC bit in the the CONFIG3L.

EDIT: RTCWREN can't simply be set to one. You should follow the sequence mentioned in the datasheet

\$\endgroup\$
  • 1
    \$\begingroup\$ Thanks for you answer but if you read the question properly, you'll notice that I've mentioned Using INTRC as a clock source for RTCC which is set on CONFIG3L. \$\endgroup\$ – Suraj Bhawal Sep 7 '16 at 11:47
  • \$\begingroup\$ Please check the editted answer \$\endgroup\$ – Latchup Sep 7 '16 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.