PSOC5 ES1 trouble with RTC sample code

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I was trying to get sample code for the RTC working on my PSOC5 kit with ES1 silicone and I may be running into one of the known issues..

   

If I program and run the code, it writes to the LCD once then seems to hang.

   

If I debug and put a breakpoint in the main loop, and "play" from that breakpoint after waiting a second, it will update the LCD each time and come back to the breakpoint.  If I "Play" from the breakpoint wiht less than a second delay, it never returns to the breakpoint and never updates the LCD any more.

   

In this document on page 7, item #21:

   

http://www.cypress.com/?docID=22245

   

It states that it won't wake from sleep cleanly, and recommends defining a compiler macro for CYLIB_POWER_MANAGEMENT in the project build properties under compiler.  Being a noob, I can't seem to figure out what this means, nor can I figure out the right keywords to find any useful information on creating compiler macros to figure it out.. A little help would be greatly appreciated.  I already figured out the clock setup mentioned in the same item (I think..)

   

If I comment out the sleep routines and prevent that from happening, the RTC is alive and well and updates the LCD with no problem.  Attached is my project. (with the sleep routines commented out in the main loop

0 Likes
2 Replies
Anonymous
Not applicable

Hi dnear1,

   

 

   

Can you please attach the RTC sample code in which you were observing this issue?

   

 

   

Regards

0 Likes
Anonymous
Not applicable

Odd... I thought I attached it as a zip file previously, but the file's not there..

   

 

                                         
     Main.c    
/* ========================================
 *
 * Copyright Daniel Near, March 2011
 * All Rights Reserved
 * UNPUBLISHED, LICENSED SOFTWARE.
 *
 * CONFIDENTIAL AND PROPRIETARY INFORMATION
 * WHICH IS THE PROPERTY OF Daniel Near.
 *
 * ========================================
*/
#include <device.h>
#define CYLIB_POWER_MANAGEMENT
/*******************************************************************************
* File Name: main.c
*
* Version: 2.0
*
* Description:
*  This is source code for the datasheet example of the Real Time Clock (RTC)
*  component.
*
*  Display legend:
*   First string:
*    RTC HH:MM:SS AP
*       RTC- component's name
*       HH - hours
*       MM - minutes
*       SS - seconds
*       AP - AM/PM
*
*   Second string:
*    YY:MM:DD DW L D
*       YY - two last digits of the year
*       MM - month
*       DD - day of month
*       DW - day of week
*       L - present if year is leap year
*       D - DST is active
*
*******************************************************************************/

#include <device.h>
#include "utils.h"


/*******************************************************************************
* Function Name: main
********************************************************************************
* Summary:
*  Main function performs following functions:
*   1. Declares date and time structure and fill it with the initial values
*   2. Enables global interrupts
*   3. Sets initial time and date values
*   4. Sets alarm date, time and mask
*   5. Sets interval mask
*   6. Sets DST start and stop configuration
*   7. Prints current date and time values.
*   8. Afterwards, device is continuosly switched to the Sleep low power mode.
*      When the 1PPS event occurs device wakes up, ISR is executed and device
*      is switched to the Sleep mode again till the next 1PPS event.
*     
*
*   The information on the display is updated in the ISR.
*
* Parameters:
*  None.
*
* Return:
*  None.
*
*******************************************************************************/
void UpdateLCDTime()
{
    uint8 tmpVar = 0u;

   /* Print current time */
    tmpVar = RTC_ReadSecond();
    PrintDecNumber(tmpVar, 0u, 11u);
    tmpVar = RTC_ReadMinute();
    PrintDecNumber(tmpVar, 0u, 8u);
    tmpVar = RTC_ReadHour();
    PrintDecNumber(tmpVar, 0u, 5u);
   tmpVar = RTC_ReadDayOfMonth();
    PrintDecNumber(tmpVar, 1u, 0u);
   
    /* Get and print month */
    tmpVar = RTC_ReadMonth();
    PrintDecNumber(tmpVar, 1u, 3u);
   
    /* Get and print year */
    tmpVar = (uint8)(RTC_ReadYear() % 100u);
    PrintDecNumber(tmpVar, 1u, 6u);

}
void main()
{
    uint8 tmpVar = 0u;

    RTC_TIME_DATE Start;

    /* Fill struct with date and time */
    Start.Sec = 55u;
    Start.Min = 59u;
    Start.Hour = 22u;
    Start.DayOfMonth = 31u;
    Start.Month = 12u;
    Start.Year = 2007u;

    /* Enable all interrupts */
    CYGlobalIntEnable;

    /* Set date and time */
    RTC_WriteTime(&Start);

    /* Set alarm date and time */
    RTC_WriteAlarmSecond(5u);
    RTC_WriteAlarmMinute(3u);
    RTC_WriteAlarmHour(1u);
    RTC_WriteAlarmDayOfMonth(1u);
    RTC_WriteAlarmMonth(1u);
    RTC_WriteAlarmYear(2008u);

    /* Set alarm mask */
    RTC_WriteAlarmMask(RTC_ALARM_SEC_MASK   | RTC_ALARM_MIN_MASK        |
                       RTC_ALARM_HOUR_MASK  | RTC_ALARM_DAYOFMONTH_MASK |
                       RTC_ALARM_MONTH_MASK | RTC_ALARM_YEAR_MASK);

    /* Set interval mask - handling of interrupt stubs of the RTC component */
    RTC_WriteIntervalMask(RTC_INTERVAL_SEC_MASK  | RTC_INTERVAL_MIN_MASK   |
                          RTC_INTERVAL_HOUR_MASK | RTC_INTERVAL_DAY_MASK   |
                          RTC_INTERVAL_WEEK_MASK | RTC_INTERVAL_MONTH_MASK |
                          RTC_INTERVAL_YEAR_MASK);

    /* DST start configuration */
    RTC_WriteDSTMode(RTC_DST_ENABLE | RTC_DST_FIXDATE);
    RTC_WriteDSTStartHour(23u);
    RTC_WriteDSTStartDayOfMonth(31u);
    RTC_WriteDSTStartMonth(12u);

    /* DST stop configuration */
    RTC_WriteDSTStopHour(2u);
    RTC_WriteDSTStopDayOfMonth(1u);
    RTC_WriteDSTStopMonth(1u);
    RTC_WriteDSTOffset(123u);

    /* Start RTC */
    RTC_Start();

    /* Start LCD */
    LCD_Start();

    /* Prepare 0th column */
    LCD_Position(0u, 0u);
    LCD_PrintString("RTC    :  :  ");

    /* Print current time */
    tmpVar = RTC_ReadSecond();
    PrintDecNumber(tmpVar, 0u, 11u);
    tmpVar = RTC_ReadMinute();
    PrintDecNumber(tmpVar, 0u, 8u);
    tmpVar = RTC_ReadHour();
    PrintDecNumber(tmpVar, 0u, 5u);

    /* Prepare 1st column */
    LCD_Position(1u, 0u);
    LCD_PrintString("  -  - ");

    /* Get and print day of month */
    tmpVar = RTC_ReadDayOfMonth();
    PrintDecNumber(tmpVar, 1u, 0u);
   
    /* Get and print month */
    tmpVar = RTC_ReadMonth();
    PrintDecNumber(tmpVar, 1u, 3u);
   
    /* Get and print year */
    tmpVar = (uint8)(RTC_ReadYear() % 100u);
    PrintDecNumber(tmpVar, 1u, 6u);
   
    /* Get and print day of week */
    tmpVar = RTC_currentTimeDate.DayOfWeek;
    LCD_Position(1u, 9u);
    LCD_PutChar(tmpVar + 0x30u);

    /* Get status */
    tmpVar = RTC_ReadStatus();
   
    /* Get and print if year is leap */
    if(RTC_STATUS_LY & tmpVar)
    {
        LCD_Position(1u, 11u);
        LCD_PutChar('L');
    }
    else
    {
        LCD_Position(1u, 11u);
        LCD_PutChar(' ');
    }

    /* Get and print daytime AM/PM */
    if(RTC_STATUS_AM_PM & tmpVar)
    {
        LCD_Position(0u, 14u);
        LCD_PrintString("PM");
    }
    else
    {
        LCD_Position(0u, 14u);
        LCD_PrintString("AM");
    }

    /* Get and print DST status */
    if (RTC_STATUS_DST & tmpVar)
    {
        LCD_Position(1u, 13u);
        LCD_PutChar('D');
    }
    else
    {
        LCD_Position(1u, 13u);
        LCD_PutChar(' ');
    }

    /* Get and print alarm status */
    if (RTC_STATUS_AA & tmpVar)
    {
        LCD_Position(1u, 15u);
        LCD_PutChar('A');
    }
    else
    {
        LCD_Position(1u, 15u);
        LCD_PutChar(' ');
    }

    while(1u)
    {
        /* Make a 100 ms delay */
        CyDelay(100);
        UpdateLCDTime();
       
        /* Prepare clock tree configuration for low power mode entry */
       // CyPmSaveClocks();//disabled to figure out the issue where it won't come back from sleep
       
        /* Disable RTC interrupt before entering Sleep mode. The device will
        *  wake up on one pulse-per-second event, but the ISR will be executed
        *  when RTC interrupts will be enabled, after the clocks configuration
        *  will be restores. Potentially, this will allow to execute RTC ISR
        *  quicker, as CyPmSaveClocks() function could decrease master clock
        *  frequency.
        */
        //RTC_DisableInt();//disabled to figure out the issue where it won't come back from sleep
       
        /* Go to the Sleep Mode. The RTC will act as a wake up source */
        //CyPmSleep(PM_SLEEP_TIME_NONE, PM_SLEEP_SRC_ONE_PPS);//disabled to figure out the issue where it won't come back from sleep
        /* Get interrupt status */
        //CyPmReadStatus(CY_PM_ONEPPS_INT);//disabled to figure out the issue where it won't come back from sleep
       
        /* Restore clock tree configuration after low power mode exit */
        //CyPmRestoreClocks();//disabled to figure out the issue where it won't come back from sleep
       
        /* Enable RTC interrupt for ISR to be executed on restored clock
        *  frequency.
        */
        //RTC_EnableInt();//disabled to figure out the issue where it won't come back from sleep
    }
}


/* [] END OF FILE */
 
   

 

                                         
     Utils.c    
/*******************************************************************************
* File Name: utils.c
*
* Version: 2.0
*
* Description:
*  This is source code library for the data sheet example project of the
*  Real Time Clock (RTC) component.
*
*******************************************************************************/

#include "utils.h"
#include <device.h>


/*******************************************************************************
* Function Name: PrintDecNumber
********************************************************************************
* Summary:
*  Prints decimal value of the number at a specified row and column of
*  LCD character display named LCD.
*
* Parameters:
*  uint8 num - Number to be printed.
*  uint8 row - Display row where to print.
*  uint8 col - Display column where to print.
*
* Return:
*  None.
*
*******************************************************************************/
void PrintDecNumber(uint8 num, uint8 row, uint8 col) CYREENTRANT
{
    uint8 tmp1 = 0u;
    uint8 tmp10 = 0u;
    LCD_Position(row, col + 1u);

    tmp1 = num % 10u;
    LCD_PutChar(tmp1 + 0x30u);

    tmp10 = num / 10u;

    LCD_Position(row, col);
    LCD_PutChar(tmp10 + 0x30u);
}


/* [] END OF FILE */
 
                                         
     Utils.h    
/*******************************************************************************
* File Name: utils.h
*
* Version: 2.0
*
* Description:
*  This is header file of the source code library for the datasheet example
*  project of the Real Time Clock (RTC) component.
*
*******************************************************************************/

#if !defined(UTILS_H)
    #define UTILS_H

    #include "cytypes.h"

    void PrintDecNumber(uint8 num, uint8 row, uint8 col) CYREENTRANT;

#endif  /* UTILS_H */
 
0 Likes