This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC430F5137: CC430F5137 RTC Calendar Mode

Part Number: CC430F5137

Hi,

I have been working with TI CC430F5137 MCU for quite sometime. I am using RTC in calendar mode (hexadecimal format) and I have been able to read hour,minute and seconds data. But I also want to read the year data from the registers and I have initially set the registers as follows: 

RTCYEARL = 0xE1;
RTCYEARH = 0x07;   corresponding to 2017.

Any suggestions would be of great help.

Thanks,

Sushmitha R

  • Hi Sushmitha,

    Please expand on the issue you are encountering because RTCYEARL/RTCYEARH are RW registers just like RTCHOUR, RTCMIN, and RTCSEC and can be read in a similar fashion.

    Regards,
    Ryan
  • Hi Ryan,

    Thanks for your reply.

    I'm currently loading decimal values into hour, minute and seconds and reading them using a read function. But in the case of year they're two different registers with higher and lower byte loaded with hex value. Could you please help me on reading the year value in decimal format.

    Thanks,

    Sushmitha R

  • Take a 16 bit variable and assign it to the value of RTCYEARL + RTCYEARH bit shifted left 8 times, something like this:

    unsigned int year = RTCYEARH;
    year = (year << 8) + RTCYEARL;

    This code is untested and must be verified first, but the result should be 0x7E1 (decimal 2017). Then convert this value from hexadecimal to whichever format you prefer.

    Regards,
    Ryan
  • Or, if you prefer math to bitshifting:

    unsigned int year = RTCYEARH;
    year = (year * 256) + RTCYEARL;

    or in one line:
    int year = RTCYEARH * 256 + RTCYEARL;

    which will probably be turned into a shift by the compiler, anyway. 8^)

    (Ryan, you were totally correct, but this might help Sushmitha R see what is going on.)

**Attention** This is a public forum