This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3100BOOST: Using WiFi + RTC_C at the same time in Energia

Prodigy 150 points

Replies: 5

Views: 1004

Part Number: CC3100BOOST

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?  I assuming I'm missing something...

One interesting note, if I start/disconnect my WiFi before I initialize the RTC_C, then WiFi start/disconnect works fine after the RTC_C stuff.   So it looks like the Energia WiFi calls are initializing something that I'm missing...Additionally, if I add in a sl_Stop after my initial disconnect before the RTC_C stuff (to reduce power consumption), then I cannot restart the WiFi later...So it looks like the sl_Stop command is then taking away that initial something.  My guess would be this is all interrupt related, but I cannot figure out quite what is going wrong...

jrd

 

-----

 

 

// 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
#endif
#ifndef cWiFiPassword
cWiFiPassword should be #define as the name of your WiFi password
#endif

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

// Main setup section
void setup() {

    // Turn on serial output
    Serial.begin(115200);
    Serial.println("");

    // Enable the clock
    RTC_C_startClock();

    // Set an alarm
    RTC_C_setCalendarAlarm( 0, RTC_C_ALARMCONDITION_OFF, RTC_C_ALARMCONDITION_OFF, RTC_C_ALARMCONDITION_OFF);
    RTC_C_registerInterrupt(vRtcIsr);
    RTC_C_enableInterrupt(RTC_C_CLOCK_ALARM_INTERRUPT);

}

// Main loop section
void loop() {

    // Start WiFi
    Serial.println("Attempting to turn on Wifi");
    WiFi.begin(cWiFiSSID,cWiFiPassword);
    Serial.println("Success");

    // Hang forever
    for(;;);

}

5 Replies

  • Hi Justin,

    I am checking internally to see if there is a possible interrupt conflict that we are aware of on the CC3100 side, but as Energia supports their own software, they may have more insight into how the Wifi library is written. You may get a more complete answer on their CC3XXX forum: forum.43oh.com/.../

    Is the rtc_c.h you are including out of the MSP432Ware driverlib?

    Best regards,
    Sarah
  • In reply to Sarah P:

    Ok, great.

    Yeah, I started my hunt for the solution to this issue on the 43oh.com site (http://forum.43oh.com/topic/10116-using-rtc-c-alarm-and-wifi-at-the-same-time/

    I'm using rtc_c.h out of the driverlib stuff that is shipped with Energia 18 (which appears in the Energia15 directory).  In the header it says:  MSP432 DriverLib - v3_21_00_05    Maybe I'll compare that with the latest driverlib stuff and see if I can figure out what is different.

  • Justin,

    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
      RTC_C_clearInterruptFlag(RTC_C_CLOCK_ALARM_INTERRUPT);
    }
    
    /* Time is November 12th 1955 10:03:00 PM */
    const RTC_C_Calendar currentTime =
    {
      0x00,
      0x03,
      0x22,
      0x12,
      0x11,
      0x1955
    };
    
    uint32_t x = 0x04;
    Hwi_Params params;
    
    void setup() {
      // Initialize Serial
      Serial.begin(115200);
      Serial.println("Setting up RTC");
    
      // Set current time
      RTC_C_initCalendar(&currentTime, RTC_C_FORMAT_BCD);
      // Set an alarm
      RTC_C_setCalendarAlarm(x, 0x22, RTC_C_ALARMCONDITION_OFF, RTC_C_ALARMCONDITION_OFF);
    
      // Register interrupt
      Hwi_Params_init(&params);
      Hwi_create(INT_RTC_C, vRtcIsr, &params, NULL);
      // RTC_C_registerInterrupt(vRtcIsr);
      Interrupt_enableInterrupt(INT_RTC_C);
    
      // Clear the interrupt
      RTC_C_clearInterruptFlag(RTC_C_CLOCK_ALARM_INTERRUPT);
      // Enable the interrupt
      RTC_C_enableInterrupt(RTC_C_CLOCK_ALARM_INTERRUPT);
      // Enable the clock
      RTC_C_startClock();
    
    }
    
    void loop() {
      // Small delay to allow for Serial to be flushed.
      delay(1000);
      // End serial to remove power constraints
      Serial.end();
    
      // Stop the watchdog and remove power constraints
      stopWatchdog();
      
      /* go to DEEPSLEEP_1 */
      Power_sleep(PowerMSP432_DEEPSLEEP_0);
    
      startWatchdog();
      // Reinitialize Serial 
      Serial.begin(115200);
      Serial.println("Woken up");
      
      x++;
    
      // Set the alarm for now + 1 min
      RTC_C_setCalendarAlarm(x, 0x22, RTC_C_ALARMCONDITION_OFF, RTC_C_ALARMCONDITION_OFF);
    }
    
    void startWatchdog() {
      // Clear the watchdog timer
      WDT_A_clearTimer();
      // Start the watchdog timer
      WDT_A_startTimer();
    }
    
    void stopWatchdog() {
      // Hold the watchdog timer 
      WDT_A_holdTimer();
    
      // Remove power constraints. Do not allow LPM4 since this kills the RTC
      Power_setConstraint(PowerMSP432_DISALLOW_DEEPSLEEP_1);
      Power_releaseConstraint(PowerMSP432_DISALLOW_DEEPSLEEP_0);
    }
    

  • In reply to Robert Wessels:

    Thanks! Switching to the Hwi stuff to register the interrupt (and adding arguments into the ISR) was exactly what I needed. RTC + WiFi now works fine...Now if I can just figure out why my RTC clock accuracy is only 3000ppm :) ...
  • In reply to Justin Davis36:

    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);

    3) Tell the RTC to use LFXT: MAP_CS_initClockSignal(CS_BCLK,CS_LFXTCLK_SELECT,CS_CLOCK_DIVIDER_1);

    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...

    jrd

    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();

This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.