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.

Set new time value for real time clock MSP430FG4618

I want to set the initial value for real time clock module. And then, if I want to set new time (decide by user) then the real time clock must update new value of time and then continue counting. Can anyone help me how to solve this problem. Thanks very much!

  • Nguyen Hoa1 said:
    I want to set the initial value for real time clock module.

    So just do it. Write the new values to the registers. You should set RTCHOLD before writing, and clear it after.

    Required configuration and usage are described in detail in the users guide. AFAIK there is nothing special about it. Provide a 32768Hz clock (Crystal on XT1), configure the RTC, write the initial values and let it count crystal oscillations.

  • Firstly, I successfully get the time from the RTC module and print it on the screen via Terminal. But I don't know how to update the new value for single byte. I use register RTCSEC, RTCMIN and RTCHOUR for setting the initial value. I want to set the new time on computer and then the RTC module can understand and continue counting. How can they understand the frame hh:mm:ss and write hh to RTCHOUR, mm to RTCMIN and sec to RTCSEC directly?

  • So yo send a string "12:34:56" to the MSP and want to parse it and write it into the RTC registers? Well, that's a plain C coding problem.

    You have two options. If you program the RTC to have its registers in binary mode, you*ll have to parse the text. You can use the standard C library functions atoi() or scanf() for this.

    If you are running the RTS in BCD mode, things are easier. You can parse the string letter by letter.
    Assuming the whole text is in an array time[] you can do

    RTCHOUR = ((time[0]-'0')<<8)|(time[1]-'0');
    RTCMIN = ((time[3]-'0')<<8)|(time[4]-'0');
    RTCSEC = ((time[6]-'0')<<8)|(time[7]-'0');

    You should precede it by setting RTCHOLD before and clearing it after.

    Also you might want to check the string for errors. e.g. test whether time[2] and time[5] are ':'. And whether the digits are digits (>='0' and <= '9') etc. Maybe even test the range (time[0]>='0' and <='2') etc.

**Attention** This is a public forum