Jump to content

Using RTC_C alarm and WiFi at the same time

Recommended Posts

Windows 7 / Code Composer Studio 7 / Energia 18 / MSP 432 LaunchPad + CC3100 WifI


I'd like to use a RTC_C calendar alarm to turn on/off my some streaming data collection, however, it doesn't seem to work.  That is, once I register the RTC_C interrupt via RTC_C_registerInterrupt,  I'm unable to init the WifI.  Specifically it hangs here in WiFi.cpp:

        int iRet = sl_Start(NULL, NULL, NULL);


I've whittled my code down to what appears below.  Does anyone have any ideas?






// Header files
#include <WiFi.h>                         // Energia
#include <driverlib/MSP432P4xx/rtc_c.h>

#ifndef cWiFiSSID
cWiFiSSID should be #define as the name of your WiFi SSID
#ifndef cWiFiPassword
cWiFiPassword should be #define as the name of your WiFi password

void vRtcIsr() {
    // Clear the flag, but don't actually do anything

// Main setup section
void setup() {

    // Turn on serial output

    // Enable the clock

    // Set an alarm


// Main loop section
void loop() {

    // Start WiFi
    Serial.println("Attempting to turn on Wifi");

    // Hang forever



Edited by bluehash
[ADMIN] Please use code tags<> next time. Thank you!
Link to post
Share on other sites

I want the device to wake up once an hour, stream some data and then go back to sleep...So, I DO want the login to be inside a loop.  For purposes of this issue, it doesn't matter though...all commands can be in the setup, all in the loop, or a mixture...regardless, the same problem occurs.  For the code I provided, I was just trying to minimize things to just the bare-bones level.


In the real code, I have a simple handler *.ino loop which is waiting on an Event.  When the calendar ISR get's triggered, all it does is send the Event which wakes up the handler loop which then starts/stops data collection depending on the time.

Link to post
Share on other sites

Made some progress, but am still having the same problem.


 First, I tried this code with CCSv6.2/E17 and had the same problems.


Second, I put a WiFi.begin/WiFi.disconnect in front of the RTC stuff in addition to after the RTC stuff....and this allowed the WiFi to start after the RTC stuff had been called.  So it seems happier letting the WiFi stuff go first....*However*, I really need more than a WiFi.disconnect, for power consumption purposes, I need to shutdown the WiFi module completely, as such I do a "sl_Stop(0)"   This works great in terms of turning off the power to the wifi module (CC3100); however, when I do a WiFi.begin/WiFi.disconnect/sl_Stop  before the RTC stuff, I can no longer re-start the WiFi after the RTC stuff again...So I'm sort of back to square one...

Link to post
Share on other sites

Oh ya, a couple other things I tried:


1) I disabled the RTC alarm and unregistered the interrupt immediately after I set it. If I do that, the WiFi still will not start.  So registering the interrupt seems to foo-bar something.


2) I ran the RTC_C demo code from the driverlib example code that I found within the resource explorer (MSP432ware).  That stuff compiled and seemed to run fine..  I do note that the example code does not use a function call to register the interrupt for the RTC_C alarm like I am doing.  They have some "startup" code which explicitly defines the list of all the interrupts.  Does energia have this somewhere?  Perhaps my use of the interrupt register function is incompatible with startup-type code????

Link to post
Share on other sites

Still trying to figure this out.  I output the hw/sw versions, do these look correct:


      H/W and S/W Versions
         CHIP: 67108864
         ROM: 13107

Link to post
Share on other sites

[ Cross posting this that what I posted on your e2e post ]


I do have low power Sketches for the CC3200 but low power handling on the CC3200 is very different from what it is on the MSP432. The MSP432 Wiring implementation is based on TI-RTOS. So hence a mix of driverlib/TI-RTOS API's need to be used to get the RTC going. I will follow up with the WiFi code later this week but below is a skeleton Sketch for the RTC:
// Header files
#include <driverlib/MSP432P4xx/rtc_c.h>
#include <driverlib/MSP432P4xx/interrupt.h>
#include <driverlib/MSP432P4xx/wdt_a.h>
#include <ti/drivers/power/PowerMSP432.h>
#include <ti/sysbios/family/arm/m3/Hwi.h>
#include <ti/drivers/Power.h>

volatile bool flag = false;

void vRtcIsr(UArg arg) {
  // Clear the flag, but don't actually do anything

/* Time is November 12th 1955 10:03:00 PM */
const RTC_C_Calendar currentTime =

uint32_t x = 0x04;
Hwi_Params params;

void setup() {
  // Initialize Serial
  Serial.println("Setting up RTC");

  // Set current time
  RTC_C_initCalendar(&currentTime, RTC_C_FORMAT_BCD);
  // Set an alarm

  // Register interrupt
  Hwi_create(INT_RTC_C, vRtcIsr, &params, NULL);
  // RTC_C_registerInterrupt(vRtcIsr);

  // Clear the interrupt
  // Enable the interrupt
  // Enable the clock


void loop() {
  // Small delay to allow for Serial to be flushed.
  // End serial to remove power constraints

  // Stop the watchdog and remove power constraints
  /* go to DEEPSLEEP_1 */

  // Reinitialize Serial 
  Serial.println("Woken up");

  // Set the alarm for now + 1 min

void startWatchdog() {
  // Clear the watchdog timer
  // Start the watchdog timer

void stopWatchdog() {
  // Hold the watchdog timer 

  // Remove power constraints. Do not allow LPM4 since this kills the RTC
Link to post
Share on other sites
  • 1 month later...
  • 2 weeks later...

FWIW, I did figure out why my RTC clock accuracy was so bad.  By default, the RTC clock sources the internal 32k crystal, not the external LFXT as BCLK.  As such, to get it to work:

1) Define frequency of LFXT to 32k:   MAP_CS_setExternalClockSourceFrequency(32768, 48000000); // LF, HF

(why energia doesn't do this already, I don't know.  I see how starting it might consume power unnecessarily, but why not set the value atleast???)

This step might not be needed, but since I wanted to query my clock speeds later, I added it.

2) Turn on LFXT (I loop on this since it doesn't always take):  bool status = MAP_CS_startLFXTWithTimeout(CS_LFXT_DRIVE3, 10);


With my msp432 launchpad, this gives me about 5ppm  (testing every 15s for about 2 weeks).

Hope this helps anyone else who might have had issues...


PS  Of course, you probably don't need to use the MAP_ versions...but I figured why not :)

PPS  This is how I was getting my actual clock speeds...ie, why I added step 1.

    // Get the values
    uint32_t aclk   = MAP_CS_getACLK();
    uint32_t mclk   = MAP_CS_getMCLK();
    uint32_t smclk  = MAP_CS_getSMCLK();
    uint32_t hsmclk = MAP_CS_getHSMCLK();
    uint32_t bclk   = MAP_CS_getBCLK();

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...