RTC Example 5LP kit 059

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

cross mob
Anonymous
Not applicable

Hi,

   

First timer here so please forgive my simple questions as new to C and Cypress, though have done a little C++ with Arduino.

   

Been working though the tutorials etc and have the RTC 5LP example running ok.

   

The first point, though cannot see anything in the RTC datasheet, wondered if  there is any way the RTC can be programmed with the current time/date automatically  taken from host PC at programming time ? a very handy feature found on the Arduino.

   

The other point is about my lack of C knowledge

   

Was amending the RTC main.c code to display on the LCD in different layouts etc, but then found that some changes had been totally ignored.

   

Found the cause to be that the same code was replicated in the RtcIntHandler.c and that was overriding the changes I made in main.c

   

So does C demand you duplicate code like this ? or was the code put in the main.c  as well,  just to make things clearer for the newbie  to see hows it was done ?

   

thanks

   

 

   

part of the code in both main.c   ---

   


    /* Print current time */
    tmpVar = RTC_ReadSecond();
    PrintDecNumber(tmpVar, 0u, 11u);  etc etc

   

 

   

and RtcIntHandler.c

   

void RTC_EverySecondHandler_Callback(void)
{
    /* Get and print current seconds */
    temp = RTC_ReadSecond();        
    PrintDecNumber(temp, 0u, 11u);
    
    /* Get status */
    temp = RTC_ReadStatus();  etc etc
  

0 Likes
6 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

You did not post your project, and my crystal ball is still in repair, so I will take an educated guess.

   

RtcInt is an ISR that you did add to the RTC? If so, then yes it will be called whenever the interrupt gets triggered. There is no need to duplicate this functionality in main (but you should not do long-running stuff in the ISR, such as writing to the LCD - better just set a (volatile) flag which main can then read and react on).

   

No, there is no automatic way to set the time from the PC, and AFAIK even the Ardiuno doesn't have that (esp. when not connected to a PC...). But you can add this by yourself quite easily via the UART.

0 Likes
Anonymous
Not applicable

Thanks for the reply.

   

Its the RtcDesign Example file for the 5LP,  that comes with PSoC v4 , not any code I have written , was just amending the code to change the layout of the lcd output when I found the problem as above.

   

Perhaps that Example code has just been quickly put together.....

   

As you say, its not good practice to use  lengthy lcd routines in the ISR  , though wondered with these faster  chips if that was still a problem vs my old 8 bit Pic chips with Assembly code !

0 Likes

Its not the MCU speed thats the problem here - the LCD will just take a while for each characters, and your code needs to wait for that to finish.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Welcome in the forum, George.

   

As hli says, it  is easier for us to help you when you post your complete project. With the help of the IDE everything is easier to follow and to check.

   

Concerning lengthy interrupt handlers: I have seen issues where just a character was sent via USB stalling the system. Usually you are not aware of delay function calls within the generated code, so hli's suggestion makes sense. Of course the code might be a bit longer, as long as you are able to overview all the consequences.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is an example program that may help you. 

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Date is set for 12/31/2007 and time is set for 22:59:22 so you will need to change this to the correct date and time.

0 Likes