1
\$\begingroup\$

Minimal Peripheral Description

To read the values from this particular RTCC peripheral you have to read the data from a single register(RTCVAL), where the information it represents is dependent on a pointer. This pointer is set by the user however decrements automatically upon each read and write to the RTCVAL register.

The description of this register looks as follows:

Description

RTCVAL is a single register, The pointers for this register (RTCPTR<1:0>) are with in another register called RCFGCAL (page 157 of datasheet linked below).

The register format is as follows:

Register Format

Problem

When trying to read the values from RTCVAL register I am not receiving information that represents a date and time format(for example receiving 30 for months).

Following is how I try to access this data:

unsigned char arr[9]; //This array will contain the RTCC Values before post process
unsigned int RTCCtemporary = 0;

RCFGCALbits.RTCPTR1 = 1; // Setting the Pointer to 11
RCFGCALbits.RTCPTR0 = 1; // So that the information given first is - Year


arr[0] = (char)RTCVAL; // Arr[0] now contains the year 
                           // The information that is pointed at by RTCVAL NOW 
                           // is Months and Days

RTCCtemporary = RTCVAL; // RTCCtemporary Holds Months and Days 
                            // Where RTCVAL Points NOW at WeekDay and Hours

arr[2] = (char)RTCCtemporary; // arr[2] now holds the Day Information    

asm("MOV _RTCCtemporary,W0");           
asm("SWAP W0");               //swapping bytes to have months first
asm("MOV W0, _RTCCtemporary");
arr[1] = (char)RTCCtemporary; //arr[1] now holds Month Information.

arr[3] = (char)RTCVAL;  // arr[3] now holds  Hours

RTCCtemporary = RTCVAL;       //RTCCtemporary now holds Minutes and seconds 
asm("MOV _RTCCtemporary,W0");           
asm("SWAP W0");               //swapping bytes to have minutes first
asm("MOV W0, _RTCCtemporary");
arr[4] = (char)RTCCtemporary; //arr[4] now holds minutes 

But of course this is not working properly, the values that I receive do not make much sense. One possible problem indicator is that when the pointer bits are being set the actual register that contains the pointer does not change to represent the new value of the pointer. That is a little worrying.

When reading through the datasheet you will also come across the matter that the RTCVAL register is only written to if RTCWREN bit is actually turned on first. To turn on RTCWREN you have to go through a unlock sequence. Remember that this is ONLY for writing to RTCVAL registers. Of course I still tried it to see if in this case it will make any difference and no it does not.

Another area of cause for this problem might be within my setup of this peripheral so I will also list that below:

    if(RCFGCALbits.RTCEN == 0) //ensures that set up is only run once.
    {
        RCFGCALbits.RTCOE = 0; 
        asm("MOV #NVMKEY, W1");
        asm("MOV #0x55, W2");
        asm("MOV W2, [W1]");
        asm("MOV #0xAA, W3");   //all Assembly represents unlock sequence
        asm("MOV W3, [W1]");
        asm("BSET RCFGCAL, #13");
        RCFGCALbits.RTCPTR1 = 1;  //pointers incremented
        RCFGCALbits.RTCPTR0 = 1;
        RTCVAL = 0x0013; // setting the year
        RTCVAL = 0x0904; // setting the Mont and Day
        RTCVAL = 0x0314; // WeekDay and Hours
        RTCVAL = 0x3000; // Minuets and Seconds
        //turn on RTCC 
        RCFGCALbits.RTCEN = 1;   //RTCC enabled 
        asm("MOV #NVMKEY, W1");
        asm("MOV #0x55, W2");
        asm("MOV W2, [W1]");   // Relocking. 
        asm("MOV #0xAA, W3");
        asm("MOV W3, [W1]");
        asm("BCLR RCFGCAL, #13");
   }

Surprisingly even at the setup the pointer changing does not seem to effect the register that contains it, maybe indicating that it is not changing at all.

The code mentioned here works if extracted into a fresh new project, however it does not work within the project that it needs to be working. The pointer does update in the fresh project therefore if someone can provide a method of how to debug a register not being initialized although the instruction is executed, will probably answer this question.

Thank you for your time.

Further Information

Although when the pointers are set and the RCFGCAL register does not change, the values pointed by the RTCVAL does change, although to a wrong value. For example if I set RTCPTR1 = 1, and RTCPTR0 = 0, It points at WEEKDay and Hours when it should be pointing at Month and Day.

Notes:

1) RTCC Reference Manual : http://ww1.microchip.com/downloads/en/DeviceDoc/39696b.pdf

2) PIC24F16KA102 Device Page: http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en539800

3) The RTCC peripheral has not been individually powered down.

\$\endgroup\$
  • \$\begingroup\$ If you're using C30 or XC16, you could use the Microchip library call RtccReadTimeDate... \$\endgroup\$ – Adam Lawrence Sep 4 '13 at 15:50
  • \$\begingroup\$ @Madmanguruman I dont think that is the problem here, the above code works in another project on its own however somehow it just does not work in the project I need it to be working in. In the project that works the pointers are actually set with the above instructions, in the project that it does not work in, the pointers are not effected by the above instruction. \$\endgroup\$ – Volcano Sep 5 '13 at 8:23
  • \$\begingroup\$ You didn't make mention of this important fact in your original question, and should update the question accordingly. \$\endgroup\$ – Adam Lawrence Sep 5 '13 at 11:50
  • \$\begingroup\$ My apologies I had not run that test when I asked the question, but I will update it now. \$\endgroup\$ – Volcano Sep 5 '13 at 14:16
1
\$\begingroup\$

Thanks to Microchips support, it turns out that the problem was with the MPLAB IDE Version 8.87.

If you have the RTCVAL register in your watch window. the instruction to set the value for the pointers appear to not take effect. Instead they are auto decremented by the watch.

\$\endgroup\$

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.