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.

CCS/MSP432P401R: RTC Date and time configuration

Part Number: MSP432P401R

Tool/software: Code Composer Studio

I have done one firmware where the user choose by hardware configuration adjust date and time. The problem is ... after the user adjust date and time I would like use the rtc to control the watch and show the current date and time in a lcd. Soo if i need use bcd code, how can I convert the user configuration in bcd code, and after show in a lcd screen converted on decimal.

  • Armando,

     It's certainly possible to set up an RTC wakeup from a low-power mode to update an output like an LCD. TI Resource Explorer provides links to the SimpleLink MSP432 SDK that has example code for running a clock/calendar using the RTC for just that purpose. This example can be found here: rtc_c_calendar_alarm_interrupt.. This example also shows how the clock/calendar information is stored. From there it would be straightforward to convert whatever user configuration information you have to/from this format.

    The data structure used by the driverlib APIs for the RTC are shown in the example as:

    //![Simple RTC Config]
    /* Time is Saturday, November 12th 1955 10:03:00 PM */
    const RTC_C_Calendar currentTime =
    {
    0x00,
    0x03,
    0x22,
    0x06,
    0x12,
    0x11,
    0x1955
    };
    //![Simple RTC Config]

    The APIs for accessing the RTCs are listed below:

    newTime = MAP_RTC_C_getCalendarTime();

    /* Initializing RTC with current time as described in time in
    * definitions section */
    MAP_RTC_C_initCalendar(&currentTime, RTC_C_FORMAT_BCD);

    /* Setup Calendar Alarm for 10:04pm (for the flux capacitor) */
    MAP_RTC_C_setCalendarAlarm(0x04, 0x22, RTC_C_ALARMCONDITION_OFF,
    RTC_C_ALARMCONDITION_OFF);

    Hope that helps.

    Regards,

      Bob L

  • i understand but i feel i came to a dead end, I developed all code, on code composer studio (CMSIS) now i need pass the configuration given by the user to the rtc variable, until now everything ok, allready done. Now how I get the current second, minute, hour...
    I need some help to solve this problem i am a bit newbie on MSP432.
  • Hello,

    I leave my code with hope someone help me. tanks in advance.

    3060.clock.c
    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    #include "msp.h"
    #include "osc.h"
    #include "adc.h"
    #include "osc.h"
    #include "buttons.h"
    #include "lcd.h"
    #include "lcd_symbols.h"
    #include "clock.h"
    #include "timer.h"
    #include "tasks.h"
    #include <stdbool.h>
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    #ifndef _CLOCK_C
    #define _CLOCK_C
    volatile uint16_t option;
    volatile uint16_t botao;
    unsigned int tempo = 0;
    char dayConf[2];
    char monthConf[2];
    char yearConf[2];
    char hourConf[2];
    char minuteConf[2];
    char secondConf[2];
    /*HH:MM:SS*/
    VAL_LCD LCDHOURS = {0,1,1};
    VAL_LCD LCDMINUTS = {0,0,0};
    VAL_LCD LCDSECONDS = {0,0,0};
    /*yy-mm-dd*/
    VAL_LCD LCDYEARS = {1,4,14};
    VAL_LCD LCDMONTH = {1,1,1};
    VAL_LCD LCDDAYS = {1,1,1};
    int Blink_pos[5]={1,4,7,10,13};
    /*STATE VARIABLES*/
    typedef enum {
    RTC_ADJ_DAY= 0,
    RTC_ADJ_MONTH,
    RTC_ADJ_YEAR,
    RTC_ADJ_HOURS,
    RTC_ADJ_MINUTES,
    RTC_ADJ_SECONDS,
    RTC_SAVE,
    RTC_CONVERTION
    } RTC_ADJSTATES; /*RTC STATE ADJUST*/
    typedef struct {
    RTC_ADJSTATES state;
    int day;
    int month;
    int year;
    int hour;
    int minutes;
    int seconds;
    int save;
    int cancel;
    } RTC_CTRL; /*RTC CONTROL STATE*/
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • now I have done some alterations on my file clock.c, and i see in the register's the clock working, so how can I get each parameter (Year, Month, Day, Hour, Minute)

  • Armando,

     If you are asking how to pull the calendar data from the RTC, this is handled by the RTC_C_getCalendarTime() API. This API returns a RTC_C_Calendar object, which has the definition shown below:

    typedef struct _RTC_C_Calendar

    {
       uint_fast8_t seconds;
       uint_fast8_t minutes;
       uint_fast8_t hours;
       uint_fast8_t dayOfWeek;
       uint_fast8_t dayOfmonth;
       uint_fast8_t month;
       uint_fast16_t year;
    } RTC_C_Calendar;

    RTC_C_Calendar currTime;

    currTime = RTC_C_getCalendarTime();

    Each Parameter is then accessed as:

    currTime->seconds
    currTime->minutes
    currTime->hours

    and so on.

    Regards,

      Bob L

     

  • Bob L thanks for your help, I solve my problem, if you want i share my solution, I have to convert decimal to BCD, to use the MSP432 RTC, and to get the real time in the LCD, I have to convert BCD to decimal, through rtc registers .

  • Armando,

      Thanks for responding, and good to hear that you found a solution. I didn't understand that it was the BCD-to-Decimal conversion that was the issue. You can skip the conversion by using the RTCBCD bit in the RTCCTL1 register to have the RTC always use decimal. You would then not need to do a conversion when reading the values and sending them to the LCD. The BCD / Decimal modes can be selected using the RTC_C_initCalendar() function. The rtc_c_calendar_alarm_interrupt.c example code shows how this can be done: 

    /* Initializing RTC with current time as described in time in definitions section */
    MAP_RTC_C_initCalendar(&currentTime, RTC_C_FORMAT_BCD);  // or Use RTC_C_FORMAT_BINARY for decimal represenation

    Just as reference for others reading this post, the RTC registers which convert BCD-to-Decimal and Decimal-to-BCD are: RTCBCD2BIN and RTCBIN2BCD. Writing to these registers and then reading back from that same register will automatically perform the stated conversion. There are equivalent driverlib calls that perform the same function:

    uint16_t RTC_C_convertBCDToBinary(uint16_t valueToConvert);     and

    uint16_t RTC_C_convertBinaryToBCD(uint16_t valueToConvert);

    Further details on the RTC registers are available in the RTC section of the MSP432 Technical Reference manual. and the Driverlib User's Guide.

    Regards,

      Bob L.

     

**Attention** This is a public forum