cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC™ 4

moshc_4060821
New Contributor II

Hello

I am using psoc4 BLE pioneer kit.

I want to generate periodic ISR using RTC after every 24 hour.

Please guide me.

thanks

MOHIT

0 Likes
1 Solution
moshc_4060821
New Contributor II

i have solve the problem.

thank you all for hellping.

here is my code.

int main()

{

    RTC_DATE_TIME alarm_time ;

    uint32_t sec, min, hour ;

    char str[128] ;

 

    init_hardware() ;

 

    sprintf(str, "RTC Alarm Test (%s %s)\n", __DATE__, __TIME__) ;

    UART_PutString(str) ;

    RTC_ClearAlarmStatus() ;

    RTC_SetAlarmHandler( alarm_handler ) ;

    RTC_SetAlarmMask( RTC_ALARM_SEC_MASK ) ; /* I only care for sec this time */

   //*for 24 hr alarm*/RTC_SetAlarmMask(RTC_ALARM_HOUR_MASK | RTC_ALARM_MIN_MASK | RTC_ALARM_SEC_MASK ) ;   

  /*  RTC_GetDateAndTime(&alarm_time) ;

 

    /* create 00:00:15 as alarm_time */

    hour = 0u ;

    min = 0u ;

   sec = 45u ;

    alarm_time.time =

        (uint32_t)(hour <<   RTC_HOURS_OFFSET) |

        (uint32_t)(min  << RTC_MINUTES_OFFSET) |

        (uint32_t)(sec) ;

     

    RTC_SetAlarmDateAndTime( &alarm_time ) ; */

RTC_DATE_TIME MyAlarm;

    RTC_DATE_TIME testReadback;   

   

    

    MyAlarm.time = RTC_SetHours( MyAlarm.time, 0 );

    MyAlarm.time = RTC_SetMinutes( MyAlarm.time, 0 );

    MyAlarm.time = RTC_SetSecond( MyAlarm.time, 45 );

    // Set the Alarm

    RTC_SetAlarmDateAndTime( &MyAlarm );

    while(1)

    {

        if (alarm_flag) {

            alarm_flag = 0 ;

            UART_PutString("ALARM! ") ;

            print_time() ;

        }

        CyDelay(200) ;

    }

}

thank you

mohit

View solution in original post

5 Replies
Yugandhar
Moderator
Moderator

Hello Mohit,

Please refer to the code example project "RTC_P4_SysTick_Example" in the PSoC Creator for basic operation of RTC.

Thanks,

P Yugandhar.

0 Likes
MotooTanaka
Esteemed Contributor

Hi,

Although I'm not the one asked this question, I also wanted to know how to use alarm.

So I downloaded "RTC_P4_SysTick_Example" and tried, but I could not figure out how to use alarm function.

Then I tried to setup alarm with the project.

As I'm not patient enough to wait 24 hours, I set the alarm for 15sec each minutes.

I called RTC_SetAlarmMask() as

RTC_SetAlarmMask(RTC_ALARM_SEC_MASK) ;

But I think that for the 24 hours version, RTC_SetAlarmMask() should be called as

RTC_SetAlarmMask(RTC_ALARM_HOUR_MASK | RTC_ALARM_MIN_MASK | RTC_ALARM_SEC_MASK ) ;

At least it seems to be working and alarm is triggered every minutes at 15 sec.

TeraTerm log

000-TeraTerm-log.JPG

main.c

===================

/*******************************************************************************

* File Name: main.c

*

* Version: 1.00

*

* Description:

*  This is the source code for the example project of the RTC_P4 component.

*

********************************************************************************

* Copyright 2015, Cypress Semiconductor Corporation. All rights reserved.

* This software is owned by Cypress Semiconductor Corporation and is protected

* by and subject to worldwide patent and copyright laws and treaties.

* Therefore, you may use this software only as provided in the license agreement

* accompanying the software package from which you obtained this software.

* CYPRESS AND ITS SUPPLIERS MAKE NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,

* WITH REGARD TO THIS SOFTWARE, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT,

* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

*******************************************************************************/

/**

* RTC Alarm Test version

* Modified on 28-Mar-2019

**/

#include <project.h>

#include <stdio.h>

/* Time: 10:59:50 */

#define TIME_HOUR           (0x10u)

#define TIME_MIN            (0x59u)

#define TIME_SEC            (0x50u)

#define TIME_HR_MIN_SEC     ((uint32)(TIME_HOUR << RTC_HOURS_OFFSET) | \

                             (uint32)(TIME_MIN  << RTC_MINUTES_OFFSET)    | \

                                      TIME_SEC)

/* Date: 03/28/2019 */

#define DATE_MONTH          (RTC_MARCH)

#define DATE_DAY            (0x28u)

#define DATE_YEAR           (0x2019u)

#define YEAR_MONTH_DAY      ((uint32)(DATE_YEAR  << RTC_YEAR_OFFSET) |\

                             (uint32)(DATE_MONTH << RTC_MONTH_OFFSET) |\

                                      DATE_DAY)

#if 0

#define DATE_MONTH_DAY_YEAR ((uint32)(DATE_MONTH << RTC_MONTH_OFFSET)   | \

                             (uint32)(DATE_DAY   << RTC_DAY_OFFSET)        | \

                                      DATE_YEAR)

#endif

#define SYSTICK_EACH_10_HZ  (10u)

#define SYSTICK_RELOAD      (CYDEV_BCLK__SYSCLK__HZ / SYSTICK_EACH_10_HZ)

/* Interrupt prototype */

CY_ISR_PROTO(SysTickIsrHandler);

volatile int alarm_flag = 0 ;

CY_ISR(alarm_handler)

{

    RTC_ClearAlarmStatus() ;

    alarm_flag = 1 ;

}

void init_hardware(void)

{

    uint32 i;

   

    /* Starts SysTick component */

    CySysTickStart();

    /* Configure SysTick timer to generate interrupt every 100 ms */

    CySysTickSetReload(SYSTICK_RELOAD);

    /* Find unused callback slot. */

    for (i = 0u; i < CY_SYS_SYST_NUM_OF_CALLBACKS; ++i)

    {

        if (CySysTickGetCallback(i) == NULL)

        {

            /* Set callback */

            CySysTickSetCallback(i, SysTickIsrHandler);

            break;

        }

    }

    /* Starts RTC component */

    RTC_Start();

    /* Set Date and Time */

    RTC_SetDateAndTime(TIME_HR_MIN_SEC,YEAR_MONTH_DAY);

    /* Set RTC time update period */

    RTC_SetPeriod(1u, SYSTICK_EACH_10_HZ);

    /* Enable global interrupts */

    CyGlobalIntEnable;

}

void print_time(void)

{

    char timeBuffer[16u];

    char dateBuffer[16u];

    uint32 time;

    uint32 date;

    /* Get Date and Time from RTC */

    time = RTC_GetTime();

    date = RTC_GetDate();

    /* Print Date and Time to UART */   

    sprintf(dateBuffer, "%04lu/%02lu/%02lu", RTC_GetYear(date), RTC_GetMonth(date), RTC_GetDay(date)) ;

    sprintf(timeBuffer, "%02lu:%02lu:%02lu", RTC_GetHours(time), RTC_GetMinutes(time), RTC_GetSecond(time));

   

    UART_PutString(dateBuffer);

    UART_PutString(" | ");

    UART_PutString(timeBuffer);

    UART_PutString("\r");   

}

/*******************************************************************************

* Function Name: main

********************************************************************************

*

* Summary:

*  At the beginning of the main function, the Systick timer starts and

*  initializes interrupt generation every 100 ms and sets the current Date and

*  Time using API. After Data and Time from RTC is obtained, print them to UART

*  in the cycle.

*

* Parameters:

*  None.

*

* Return:

*  None.

*

*******************************************************************************/

int main()

{

    RTC_DATE_TIME alarm_time ;

    uint32_t sec, min, hour ;

    char str[128] ;

   

    init_hardware() ;

   

    sprintf(str, "RTC Alarm Test (%s %s)\n", __DATE__, __TIME__) ;

    UART_PutString(str) ;

    RTC_ClearAlarmStatus() ;

    RTC_SetAlarmHandler( alarm_handler ) ;

    RTC_SetAlarmMask( RTC_ALARM_SEC_MASK ) ; /* I only care for sec this time */

   

    RTC_GetDateAndTime(&alarm_time) ;

   

    /* create 00:00:15 as alarm_time */

    hour = 0u ;

    min = 0u ;

    sec = 15u ;

    alarm_time.time =

        (uint32_t)(hour <<   RTC_HOURS_OFFSET) |

        (uint32_t)(min  << RTC_MINUTES_OFFSET) |

        (uint32_t)(sec) ;

       

    RTC_SetAlarmDateAndTime( &alarm_time ) ;   

    while(1)

    {

        if (alarm_flag) {

            alarm_flag = 0 ;

            UART_PutString("ALARM! ") ;

            print_time() ;

        }

        CyDelay(200) ;

    }

}

/*******************************************************************************

* Function Name: SysTickIsrHandler

********************************************************************************

* Summary:

*  The interrupt handler for SysTick interrupts.

*

* Parameters:

*  None

*

* Return:

*  None

*

*******************************************************************************/

void SysTickIsrHandler(void)

{

    RTC_Update();

}

/* [] END OF FILE */

===================

moto

moshc_4060821
New Contributor II

hi motoo tanaka

thanks for helping me. by using your method i am able to generate alarm @  15th second.

but as i have modified the second 15 to 45 alarm is generated on 33rd seconds. i could not understand why.

this is the code

int main()

{

    RTC_DATE_TIME alarm_time ;

    uint32_t sec, min, hour ;

    char str[128] ;

  

    init_hardware() ;

  

    sprintf(str, "RTC Alarm Test (%s %s)\n", __DATE__, __TIME__) ;

    UART_PutString(str) ;

    RTC_ClearAlarmStatus() ;

    RTC_SetAlarmHandler( alarm_handler ) ;

    RTC_SetAlarmMask( RTC_ALARM_SEC_MASK ) ; /* I only care for sec this time */

  

    RTC_GetDateAndTime(&alarm_time) ;

  

    /* create 00:00:15 as alarm_time */

    hour = 0u ;

    min = 0u ;

   sec = 45u ;

    alarm_time.time =

        (uint32_t)(hour <<   RTC_HOURS_OFFSET) |

        (uint32_t)(min  << RTC_MINUTES_OFFSET) |

        (uint32_t)(sec) ;

      

    RTC_SetAlarmDateAndTime( &alarm_time ) ;  

    while(1)

    {

        if (alarm_flag) {

            alarm_flag = 0 ;

            UART_PutString("ALARM! ") ;

            print_time() ;

        }

        CyDelay(200) ;

    }

}

please guide me.

mohit

0 Likes
moshc_4060821
New Contributor II

i have solve the problem.

thank you all for hellping.

here is my code.

int main()

{

    RTC_DATE_TIME alarm_time ;

    uint32_t sec, min, hour ;

    char str[128] ;

 

    init_hardware() ;

 

    sprintf(str, "RTC Alarm Test (%s %s)\n", __DATE__, __TIME__) ;

    UART_PutString(str) ;

    RTC_ClearAlarmStatus() ;

    RTC_SetAlarmHandler( alarm_handler ) ;

    RTC_SetAlarmMask( RTC_ALARM_SEC_MASK ) ; /* I only care for sec this time */

   //*for 24 hr alarm*/RTC_SetAlarmMask(RTC_ALARM_HOUR_MASK | RTC_ALARM_MIN_MASK | RTC_ALARM_SEC_MASK ) ;   

  /*  RTC_GetDateAndTime(&alarm_time) ;

 

    /* create 00:00:15 as alarm_time */

    hour = 0u ;

    min = 0u ;

   sec = 45u ;

    alarm_time.time =

        (uint32_t)(hour <<   RTC_HOURS_OFFSET) |

        (uint32_t)(min  << RTC_MINUTES_OFFSET) |

        (uint32_t)(sec) ;

     

    RTC_SetAlarmDateAndTime( &alarm_time ) ; */

RTC_DATE_TIME MyAlarm;

    RTC_DATE_TIME testReadback;   

   

    

    MyAlarm.time = RTC_SetHours( MyAlarm.time, 0 );

    MyAlarm.time = RTC_SetMinutes( MyAlarm.time, 0 );

    MyAlarm.time = RTC_SetSecond( MyAlarm.time, 45 );

    // Set the Alarm

    RTC_SetAlarmDateAndTime( &MyAlarm );

    while(1)

    {

        if (alarm_flag) {

            alarm_flag = 0 ;

            UART_PutString("ALARM! ") ;

            print_time() ;

        }

        CyDelay(200) ;

    }

}

thank you

mohit

View solution in original post

MotooTanaka
Esteemed Contributor

Dear Mohit-san,

Thank you very much for your correcting my code!

Now I learned how to set the time correctly.

Best Regards,

4-Apr-2019

Motoo Tanaka

0 Likes