1 2 Previous Next 18 Replies Latest reply on Nov 27, 2014 6:43 AM by MichaelF_56

    how to config RTC use external 32.768?

      1.how to config RTC use external 32.768?

         Find in rtc.h,but i can`t find how to config.

      2.Is there a function that i can regeist the  RTC interupt for seconds function?

        • 1. Re: how to config RTC use external 32.768?
          jota_1939431

          Hello dongzaiq,

           

          Look at the rtc.h in the SDK Directory:

          ..\WICED\WICED-Smart-SDK-x.x.x\WICED-Smart-SDK\include\Drivers\rtc.h

           

          You may also want to look at similar posts that address the RTC:

          Internal vs. External Oscillator

           

          Let me know if this helps.

           

          JT

          • 2. Re: how to config RTC use external 32.768?

            rtc.h

            enum

            {

                RTC_REF_CLOCK_SRC_32KHZ  = 32,

                RTC_REF_CLOCK_SRC_128KHZ = 128

            };

            This  is only a enum.

            But I can`t find where used it.

            According to the normal way: RTC_REF_CLOCK_SRC_32KHZ or RTC_REF_CLOCK_SRC_128KHZ shoud be input  parameter!

            jota_1939431

            • 3. Re: how to config RTC use external 32.768?
              jota_1939431

              Hello dongzaiq,

               

              Are you using the BCM20732 or BCM20736?

               

              Here is the rtc sample.

              1. You need the external 32K xtal hooked up to P26/P27 or comment out the use 32K #define to use the internal 128K instead – This is not very accurate so it will drift within minutes).
              2. Backup and replace Wiced-Smart/tier2 directory with the files in the attached .zip file.
              3. Create <SDK>/Apps/rtc_sample/ and place the rtc_sample.c and makefile.mk in it.
              4. Create a make target called rtc_sample-BCM92073xTAG_Q32, then build and download.
              5. Hook up P0 to GND

               

              Here is the code:

               

              $ Copyright Broadcom Corporation $
              */

              /** @file
              *
              * RTC Sample
              *
              * This application provides the sample code for interfacing with
              * the on-chip RTC clock. It is highly recommended that an external 32K
              * xtal be used when accurate time is to be maintained. The accuracy
              * of the time maintained with the an external LPO is an order of magnitude
              * better than the internal LPO.
              *
              *
              * Features demonstrated
              *  - Use of the on-chip RTC interface.
              *  - Use of the external 32 KHz LPO when available for sleep and deep sleep.
              *  - Entering deep sleep on demand.
              *  - Using the internal or the external LPO (32KHz xtal) for timed wake from deep sleep.
              *
              * To demonstrate the app, work through the following steps.
              * 1. Plug the WICED eval board into your computer
              * 2. Build and download the application (to the WICED board)
              * 3. Application initializes and RTC and prints time every second.
              * 3.a Application programs and enters deepsleep, optionally configuring for a timed wake.
              */
              #define CONFIG_IN_NVRAM 1

              // Uncomment #define RTC_SAMPLE_USE_EXSTERNAL_32K_OSC_REFERENCE below to enable using
              // the external 32K LPO (make sure that R102 and R103 on BCM920737TAG_Q32 is populated
              // with a 0 Ohm resistor, else the the behavior is undefined).
              #define RTC_SAMPLE_USE_EXSTERNAL_32K_OSC_REFERENCE

              // Uncomment the #define RTC_SAMPLE_ENTER_DEEP_SLEEP_AND_ENABLE_TIMED_WAKE below to
              // see how to enter deep sleep on demand and also program timed wake using either
              // the internal LPO or the external 32KHz xtal (see
              // RTC_SAMPLE_USE_EXSTERNAL_32K_OSC_REFERENCE above).
              #define RTC_SAMPLE_ENTER_DEEP_SLEEP_AND_ENABLE_TIMED_WAKE

              #include "bleprofile.h"
              #include "bleapp.h"
              #include "gpiodriver.h"
              #include "string.h"
              #include "stdio.h"
              #include "platform.h"
              #include "bleappconfig.h"
              #include "cfa.h"
              #include "rtc.h"
              #include "bleapputils.h"
              #include "bleapp.h"
              #include "devicelpm.h"
              #include "miadriver.h"

              /******************************************************
              *                      Constants
              ******************************************************/

              /******************************************************
              *               Function Prototypes
              ******************************************************/
              static void rtc_sample_create(void);
              static void rtc_sample_timeout(UINT32 arg);
              static void rtc_sample_fine_timeout(UINT32 arg);

              /******************************************************
              *               Variables Definitions
              ******************************************************/

              // Following structure defines UART configuration
              const BLE_PROFILE_PUART_CFG rtc_sample_puart_cfg =
              {
                  /*.baudrate   =*/ 115200,
                  /*.txpin      =*/ GPIO_PIN_UART_TX,
                  /*.rxpin      =*/ GPIO_PIN_UART_RX,
              };

              /******************************************************
              *               Function Definitions
              ******************************************************/

              // Application initialization
              APPLICATION_INIT()
              {
                  bleapp_set_cfg(NULL, 0, NULL, (void *)&rtc_sample_puart_cfg, NULL, rtc_sample_create);
              }

              // Create the RTC sample.
              void rtc_sample_create(void)
              {
                  RtcTime current_time;
              char buffer[64];

                  ble_trace0("rtc_sample_create()\n");

                  if (!mia_isResetReasonPor())
                  {
                   ble_trace0("Waking from deep sleep because the timer went off or a GPIO triggered while waiting for timer to expire.");
                  }
                  else
                  {
                   ble_trace0("Not a timed wake.");
                  }

                  blecm_configFlag |= BLECM_DBGUART_LOG;

                  bleprofile_Init(bleprofile_p_cfg);

              #ifdef RTC_SAMPLE_USE_EXSTERNAL_32K_OSC_REFERENCE
              // If we need to use the external 32K, then configure the reference
              rtcConfig.oscillatorFrequencykHz = RTC_REF_CLOCK_SRC_32KHZ;

              // Since the 32K external LPO is connected tp P10, P11, P12, P26 and P27,
              // input and putput disable all 5 GPIOs.
              gpio_configurePin(0, 10, GPIO_INPUT_DISABLE, 0);
              gpio_configurePin(0, 11, GPIO_INPUT_DISABLE, 0);
              gpio_configurePin(0, 12, GPIO_INPUT_DISABLE, 0);
              gpio_configurePin(1, 10, GPIO_INPUT_DISABLE, 0);
              gpio_configurePin(1, 11, GPIO_INPUT_DISABLE, 0);
              #endif

                  // Initialize the RTC.
                  rtc_init();

                  memset(buffer, 0x00, sizeof(buffer));
              ble_trace0("Time base is:");

              // RtcTime of 0x00 is the start of RTC time.
                  memset(&current_time, 0x00, sizeof(current_time));
              rtc_ctime(&current_time, buffer);
              ble_trace0(buffer);

              // Let year = 2014.
              current_time.year = 2014;
              // Let month = april = 3 (jan = 0)
              current_time.month = 3;
              // Let day = 1st.
              current_time.day = 1;
              // Let current time be 12:00:00 Noon.
              current_time.hour = 12;
              current_time.minute = 00;
              current_time.second = 0x00;

              // If this is a power-on reset, we need to set up the reference time.
              if (mia_isResetReasonPor())
              {
                // Now set the on-chip RTC.
                if(rtc_setRTCTime(&current_time))
                {
                 memset(buffer, 0x00, sizeof(buffer));

                 ble_trace0("Power-on reset, set current time to:");
                 rtc_ctime(&current_time, buffer);
                 ble_trace0(buffer);
                }
                else
                {
                 ble_trace0("Unable to set time.");
                }
              }
              else
              {
                // Set up the original reference time instead of using 01/01/2010, 00:00:00 as the reference
                // because this is a wake from deep sleep. The HW clock keeps running in deep sleep so when
                // we wake up, the FW needs to know what was used as the original reference time.
                rtc_setReferenceTime(&current_time);
              }

                  bleprofile_regTimerCb(rtc_sample_fine_timeout, rtc_sample_timeout);
                  bleprofile_StartTimer();

              #ifdef RTC_SAMPLE_USE_EXSTERNAL_32K_OSC_REFERENCE
                  // Since we have an external 32 KHz LPO, switch to using this during sleep
                  // because this will give us a more accurate sleep clock (lower drift than the
                  // internal LPO, so the uncertainty window during a receive will be narrower).
                  // In general, base sleep current will be lower too.
                  // Switching to the external 32K with bleapputils_changeLPOSource without having
                  // initialized the RTC, the bonded GPIOs and not having the 32KHz oscillator physically
                  // connected to the chip will invoke undefined behavior.
                  bleapputils_changeLPOSource(LPO_32KHZ_OSC, FALSE, 250);
              #endif

                  // Trace out number of bytes free.
                  ble_trace1("Number of free bytes in RAM: %d",  cfa_mm_MemFreeBytes());
              }

              // One second timer expired. Read the time from RTC and print.
              void rtc_sample_timeout(UINT32 arg)
              {
              RtcTime current_time;
              UINT32 seconds_since_time_base;
              char buffer[64];
              tRTC_REAL_TIME_CLOCK raw_clock;

              memset(buffer, 0x00, sizeof(buffer));

              // Get and print current time.
              rtc_getRTCTime(&current_time);
              ble_trace0("Current date/time is:");
              rtc_ctime(&current_time, buffer);
              ble_trace0(buffer);

              // Get and print time since time base in seconds.
              rtc_RtcTime2Sec(&current_time, &seconds_since_time_base);
              ble_trace1("Its been %d seconds since bigbang.", seconds_since_time_base);

              // Get and print the raw 48 bit clock value.
              rtc_getRTCRawClock(&raw_clock);

              ble_trace2("Upper and lower 32 bit values: 0x%08X, 0x%08X\n", raw_clock.reg32map.rtc32[1], raw_clock.reg32map.rtc32[0]);

              #ifdef RTC_SAMPLE_ENTER_DEEP_SLEEP_AND_ENABLE_TIMED_WAKE
              {
                static UINT32 num_timeouts_since_boot = 0;

                // Demo going into deep sleep with wake after 5s.
                if (num_timeouts_since_boot++ >= 10)
                {
                 // If its been ~10s of ADV, configure timed wake and
                 // enter deep sleep right now.
                 ble_trace0("Entering deep sleep.");

                 gpio_configurePin(0, 0, 0x100, 0);

                 // Configure the low power manager to enter deep sleep.
                 devLpmConfig.disconnectedLowPowerMode = DEV_LPM_DISC_LOW_POWER_MODES_HID_OFF;

                 // Configure the wake time in mS.
                 devLpmConfig.wakeFromHidoffInMs = 5000;

                 // Configure the reference clock to use.

              #ifndef RTC_SAMPLE_USE_EXSTERNAL_32K_OSC_REFERENCE
                 // Use internal LPO.
                 devLpmConfig.wakeFromHidoffRefClk = HID_OFF_TIMED_WAKE_CLK_SRC_128KHZ;
              #else
                 // Use the external 32k.
                 devLpmConfig.wakeFromHidoffRefClk = HID_OFF_TIMED_WAKE_CLK_SRC_32KHZ;
              #endif

                 gpio_configurePin(0, 0, 0x100, 0);

                 // Enter deep-sleep now. Will not return.
                 devlpm_enterLowPowerMode();
                }
              }
              #endif
              }

              void rtc_sample_fine_timeout(UINT32 arg)
              {

              }

               


              Results:

               

              1. Once downloaded, hook up teraterm/hyperterm to HCI uart, disconnect RXd and reset.
              2. You should see something like this:

               

              rtc_sample_create()
              Not a timed wake.
              020106030304000409bb8104
              020a81
              Time base is:
              Jan 0 00:00:00 0000
              Power-on reset, set current time to:
              Apr 1 12:00:00 2014
              Number of free bytes in RAM: 28436

              blecm evt handler:
              0e0401082000

              blecm evt handler:
              0e0401092000
              @$*#04FF2EF7009201050000074A05197A732000074E05413E00000007362A0100000400073A2A500000000007522A50000100Current date/time is:
              Apr 1 12:00:00 2014                Prints time every 1s.
              Its been 134049600 seconds since bigbang.
              Upper and lower 32 bit values: 0x00000000, 0x00007506
              Current date/time is:
              Apr 1 12:00:01 2014
              Its been 134049601 seconds since bigbang.
              Upper and lower 32 bit values: 0x00000000, 0x0000D9B7
              Current date/time is:
              Apr 1 12:00:02 2014
              Its been 134049602 seconds since bigbang.
              Upper and lower 32 bit values: 0x00000000, 0x00015183
              ….                                             Continues to print time every 1s for 10s.
              Current date/time is:
              Apr 1 12:00:10 2014
              Its been 134049610 seconds since bigbang.
              Upper and lower 32 bit values: 0x00000000, 0x00054DD0
              Entering deep sleep.        After 10s of printing time, enters hid-off for 5s. Measure Vio and you should see ~5uA.
              rtc_sample_create()
              Waking from deep sleep because the timer went off or a GPIO triggered while waiting for timer to expire.         On wake up after 5s in hid-off, detects that this is a timed wake and not a PoR. So uses a different API to initialize reference time.
              020106030304000409bb8104
              020a81
              Time base is:
              Jan 0 00:00:00 0000
              Number of free bytes in RAM: 28436

              blecm evt handler:
              0e0401082000

              blecm evt handler:
              0e0401092000
              @$*#04FF2EF7009201050000074A05197A732000074E05413E00000007362A0100000400073A2A500000000007522A50000100Current date/time is:
              Apr 1 12:00:16 2014          Continues to print time every 1s, starting from where we left off. Its off by 1s because there is a ~1s delay before the app timer goes off + boot time. Compare with wall clock and this will still be correct.
              Its been 134049616 seconds since bigbang.
              Upper and lower 32 bit values: 0x00000000, 0x000850F4
              Current date/time is:
              Apr 1 12:00:17 2014
              Its been 134049617 seconds since bigbang.
              Upper and lower 32 bit values: 0x00000000, 0x0008C8C1
              …              Continues same sequence forever.

               

              Make file if you need it:

               

              #
              # $ Copyright Broadcom Corporation $
              #

              ########################################################################
              # Application sources.
              ########################################################################
              APP_SRC = rtc_sample.c

              ########################################################################
              ################ DO NOT MODIFY FILE BELOW THIS LINE ####################
              ########################################################################
              APP_PATCHES_AND_LIBS += rtc_api.a

               

              Let me know if this helps.

               

              JT

              • 4. Re: how to config RTC use external 32.768?

                Thank you very much ! It is very helpful!

                • 5. Re: how to config RTC use external 32.768?

                  1.

                  rtc_setReferenceTime(&current_time);

                  I use BCM20732 , SDK1.1.0 Do not have this(rtc_setReferenceTime(&current_time);) function?

                  Is there miadriver.h , devicelpm.h , cfa.h  detailed functions description ?

                  2.

                  rtcConfig.oscillatorFrequencykHz = RTC_REF_CLOCK_SRC_32KHZ at here wo have config use a extenal 32K, why we need to use

                  bleapputils_changeLPOSource(LPO_32KHZ_OSC, FALSE, 250); to chang to extenal 32K?

                  • 7. Re: how to config RTC use external 32.768?

                    Entering deep sleep. when it wake up,the RTC value will be reset!

                    But for you output info,you RTC is not reset! Is there a methor that when into sleep, the RTC be retain and not be close?

                    Is it because my RTC  use the RTC_REF_CLOCK_SRC_128KHZ,so it will be reset when boot_up?

                    • 8. Re: how to config RTC use external 32.768?
                      userc_2050

                      Hi j.t ,

                      Yes, would you know if there is an RTC function on the BCM20732S ?

                      Thanks

                      Mark

                      • 9. Re: how to config RTC use external 32.768?
                        gymic_2136431

                        Hi J.t,

                         

                        because of "rtc_api.a", i had a compile error.

                        where can i get "rtc_api.a".

                        (my sdk version is "WICED-Smart-SDK-2.0.1")

                         

                        Thanks,

                        GyoungBo Min.

                        • 10. Re: how to config RTC use external 32.768?
                          user_1710756

                          Hi J.T

                           

                          You described above like this ,

                          "2. Backup and replace Wiced-Smart/tier2 directory with the files in the attached .zip file."

                           

                          However, I can't find *.zip file anywhere. Could you provide this file asap?

                           

                          Thanks,

                          SM

                          • 11. Re: how to config RTC use external 32.768?
                            jota_1939431

                            Hello GyoungBo Min,

                             

                            We adding a few changes to the rtc_api.a and it will be released in our next SDK.

                             

                            We will let you know when it is available.

                             

                            Thank you

                             

                            JT

                            • 12. Re: how to config RTC use external 32.768?
                              gymic_2136431

                              Hi JT,

                               

                              Thanks for your answer.

                              let me know when will you release next SDK as soon as possible?
                              could i get test version(rtc_api.a or SDK)?

                               

                              Thanks,

                              GyoungBo Min

                              • 13. Re: how to config RTC use external 32.768?
                                jota_1939431

                                Hello GyoungBo,

                                 

                                The SDK 2.1.0 has just been released: WICED Smart Docs & Downloads

                                 

                                Thanks

                                JT

                                • 14. Re: how to config RTC use external 32.768?
                                  gymic_2136431

                                  hello JT

                                   

                                  thanks for your inform.

                                  i had a install problem.(check attached a file.)

                                  install_error.jpg

                                  please let me know what is the problem.(previous version works well.)

                                  Thanks

                                  GyoungBo Min

                                  1 2 Previous Next