0

I want to configure RTC of PIC24F32KA302 so that LED toggles every second. Howerver, it does not work. Please, find attach below RTC code which I write to initialize internal RTC. IDE: MPLAB X IDE Programmer: PICKit 3 Compiler: XC16

RCFGCALbits.RTCWREN = 1;
RCFGCALbits.RTCEN = 0;
while(RCFGCALbits.RTCSYNC==1);      //wait for RTCSYNC bit to become 0
ALCFGRPTbits.ALRMEN = 0;    //disable the alarm
RTCPWCbits.RTCCLK = 0;//00= External Secondary Oscillator (SOSC)
ALCFGRPTbits.AMASK = 1; //Alarm Every 1 second
ALCFGRPTbits.ARPT = 0;          //Alarm will not repeat
ALCFGRPTbits.CHIME = 0;         //Alarm CHIME Enable
ALCFGRPTbits.ALRMEN = 1 ;       //Alarm Enabled

//RTCC CONFIGURATION
RCFGCALbits.RTCOE = 0;          //RTCC output disabled
RCFGCALbits.CAL=0;              //RTC Drift Calibration
RCFGCALbits.RTCEN = 1;          //RTCC Enabled
RCFGCALbits.RTCWREN = 0;        //Disabled RTCC value write

//TODO: Investigate what this does
//PADCFG1bits.RTSECSEL = 0b11;    //RTCC Seconds Clock is not selected for the RTCC pin


//Interrupt configuration
IFS3bits.RTCIF = 0;             //Clear RTCC Alarm interrupt flag
IEC3bits.RTCIE = 1;             //RTCC Alarm interrupt Enabled

void __attribute__ ( (interrupt, no_auto_psv) )  _RTCCInterrupt(void) {
LED = ~LED;
IFS3bits.RTCIF = 0;}

Is there any problem with my code? Thank you!

uv_utna
  • 41
  • 1
  • 1
  • 3
  • Before any interrupt can occur, the Global Interrupt Enable bit must be set. This is called GIE and is found in INTCON. – Weather Vane May 27 '16 at 14:44
  • PIC24F32KA302 has INTCON1 and INTCON2 register, but there isn't GIE bit in these registers. The PIC24F32KA302 datasheet only mentions:"Global Interrupt Enable (GIE) control functions are controlled from INTCON1 and INTCON2. INTCON1contains the Interrupt Nesting Disable (NSTDIS) bit, as well as the control and status flags for the processor trap sources. The INTCON2 register controls the external interrupt request signal behavior and the use of the AIVT." – uv_utna May 27 '16 at 16:18
  • 1
    I did read that in a similar data sheet (PIC24FV32KA304) before commenting but failed to look at the *content* of `INTCON1`. What I wrote actually came from another PIC page. But usually, there is a global interrupt enable in some shape or form, so that a) you can configure multiple sources without having any causing an interrupt too soon, and b) so that you can easily suspend them all. – Weather Vane May 27 '16 at 16:31

0 Answers0