LV32MX RTCC Wont run properly

Please check the frequently asked questions before posting to the forum.
Post Reply
Author
Message
bobspencerr
Posts: 78
Joined: 17 Jun 2008 13:38

LV32MX RTCC Wont run properly

#1 Post by bobspencerr » 10 Apr 2012 09:41

Hi,
Can anyone tell me how to make the RTCC in the pic32 chips operate correctly?
The code i have is here but it is not working.

Any help appreciated.

Code: Select all

program RTCC;

var Seconds_bit : sbit at LATD6_bit;

var time : dword;
var date : dword;

begin
  AD1PCFG := 0xFFFF;         // Initialize AN pins as digital
  TRISG := 0;                // Set PORTD as output
  LATG := 0;                 // Clear PORTD
  TRISD := 0;
  LatD := 0;
  // RTCC registers unlock procedure
  SYSKEY := 0xAA996655;      // Write first unlock key to SYSKEY
  SYSKEY := 0x556699AA;      // Write second unlock key to SYSKEY
  RTCWREN_bit := 1;          // RTC Value registers can be written to by the user
  OSCCON.SOSCEN := 1; // OSCCON.SOSCEN = 1;  
  // enable secondary oscillator
  SOSCEN_bit := 1;
  OSCCONSET := 2;
  while( not SOSCRDY_bit) do// wait for secondary oscillator to stabilize
    ;
  RTCOE_bit := 1;            // RTCC pin clock output enabled
  RTSECSEL_bit := 1;         // RTCC Seconds Clock is selected for the RTCC pin

  ON__RTCCON_bit:= 1;        // Turn on the RTCC module

  while(not (RTCCON and 0x40)) do     // Wait for clock to be turned on
    ;
  LATA := 0;                 // Clear PORTD
  while(1) do LATD.2 := RTCTIME.B8;   // Toggle Seconds_bit every second

end.


bobspencerr
Posts: 78
Joined: 17 Jun 2008 13:38

Re: LV32MX RTCC Wont run properly

#3 Post by bobspencerr » 10 Apr 2012 10:38

Ok,

I have now got this code but still no go......
Where am I going wrong?

Code: Select all

program RTCC;

var Seconds_bit : sbit at LATD6_bit;

var time : dword;
var date : dword;

procedure RTCCInterrupt(); iv IVT_RTCC; ilevel 3; ics ICS_AUTO;
begin
     portD.1 := not portD.1;
     IFS1CLR :=0x00008000; // clear RTCC existing event
     IPC8CLR :=0x1f000000; // clear the priority
     IPC8SET :=0x0d000000; // Set IPL=3, subpriority 1

end;

procedure rtc_enable();
begin
    DisableInterrupts();
    //unlock
    SYSKEY := 0XAA996655;
    SYSKEY := 0X556699AA;
    rtcconset := 0x8;       // write enable bit
    EnableInterrupts();       // Enable all interrupts

    OSCCON.SOSCEN := 1;   // turn on 32KHz oscillator
    delay_ms(100); // allow time for 32KHz crystal to start before enabling RTCC
    RTCCON.15 := 1;         // turn on RTCC

    IEC1CLR:=0x00008000;    // disables interrupts
    RTCCONCLR:=0x8000;       //// turn off the RTCC while
    while (RTCCON and 0x40) do nop;    //// wait for clock to be turned off

    IFS1CLR:=0x00008000;     //// clear RTCC existing event
    IPC8CLR:=0x1f000000;     //// clear the priority
    IPC8SET:=0x0d000000;     //// Set IPL=3, subpriority 1
    IEC1SET:=0x00008000;     //// Enable RTCC interrupts
    RTCALRMCLR:=0xCFFF;      // // clear ALRMEN, CHIME, AMASK and ARPT//
    ALRMTIME:=0x16154300;    //// set alarm time to 16 hr, 15 min, 43 sec
    ALRMDATE:=0x06102705;    //// set alarm date to Friday 27 Oct 2006
    RTCALRMSET:= (0xc000 or 0x00000100);
    RTCCONSET:=0x8000;            //// turn on the RTCC
    while((RTCCON and 0x40) = 0) do nop;       //// wait for clock to be turned on
end;


begin
  AD1PCFG := 0xFFFF;         // Initialize AN pins as digital
  TRISG := 0;                // Set PORTD as output
  LATG := 0;                 // Clear PORTD
  TRISD := 0;
  LatD := 0;
  portd.0 := 1;
  rtc_enable;
  
  RTCCIP0_bit := 1;                   // Set RTCC interrupt
  RTCCIP1_bit := 1;                   // priority level
  RTCCIP2_bit := 1;                   // to 7

  RTCCIE_bit := 1;          // Enable RTCC Interrupt
  EnableInterrupts();      // Enable all interrupts
  while true do 
  begin
      portd.2:= not portd.2;
      delay_ms(500);
  end;
  
end.

bobspencerr
Posts: 78
Joined: 17 Jun 2008 13:38

Re: LV32MX RTCC Wont run properly

#4 Post by bobspencerr » 10 Apr 2012 11:32

Hahahahahha,

I thought I read in the documentaion that the chip had Internal RTCC and 32khz clock source.

Apparently I have to add an external clock (32kHz and caps).

My mistake....
Sorry people

Post Reply

Return to “mikroPascal FAQ”