7 years, 7 months ago.

DeepSleep doesn't halt the program on my nucleo F401RE

Dear all, the problem I encounter is pretty simple. I inserted a "deepsleep" command in my code in which I setup an interrupt for an external rtc and a function to start when interrupt activated. THe compiler is ok, the program runs, but it doesn't go to sleep after the instruction "deepsleep". I traced with some "printf" the course of the program, here are below the program and the traces. In the traces, one can see that the program goes before and after "deepsleep" without stopping, and rebounce at the beginning of the "while" until the question asked to the user... Can someone help me to explain why it doesn't stop ? thanks a lot to you experts...

Main Code

  1. include "mbed.h"
  2. include "Ds3231Ext.h"
  3. include "userEntry.h"
  1. define TERM_HOME ("")
  2. define TERM_CLEAR_FROM_CURSOR ("")
  3. define TERM_CLEAR_EOL ("")
  1. define DS3231_WRITE_ADRS (0x68 << 1)
  2. define DS3231_READ_ADRS ((0x68 << 1) | 1)
  3. define ALARM_1_BIT (1)
  4. define ALARM_2_BIT (2)
  5. define STATUS_REG_ADRS (0x0F)

int nbInt = 0; interrupt counter int nbMain = 0; main counter int nbWhile = 0; while counter int beforeSleep = 0; int afterSleep = 0; I2C Bus I2C i2c(D5, D7);

DS3231 INT pin connected to D2 with pull-up InterruptIn rtc_int(A1);

void DS3231Int() { printf("\nEnter in DS3231Int \n"); todo printf("Exit of DS3231Int \n"); }

int main() { printf("nbMain = %i\n",nbMain++); Ds3231Ext rtc(i2c,A1); rtc_int.fall(&DS3231Int); uint32_t userAnswerNum; while(1) { printf("nbWhile = %i\n",nbWhile++); printTime(&rtc);

get answer from user get_user_input("\nDo you want to update time & calendar ? (0->no, 1->yes): ", 0, 1, &userAnswerNum);

printf("userAnswerNum = %d\n",userAnswerNum);

if (userAnswerNum == 1) { enter time and date on the DS3231 enterTime(&rtc); }

enter alarm on the DS3231 enterAlarm(&rtc); Alarm1 only

entering sleep mode printf("beforeSleep = %i\n",beforeSleep++); deepsleep(); wait(5); printf("afterSleep = %i\n",afterSleep++); } }

Main debug traces: nbMain = 0 nbWhile = 0

0Enter printTime Time as seconds since January 1, 1970 = 1494783788 Time as a basic string = Sun May 14 17:43:08 2017 Time as a custom formatted string = 05:43 PM

Exit printTime

Do you want to update time & calendar ? (0->no, 1->yes): 0userAnswerNum = 0

What Alarm time mode? 1 for 12hr 0 for 24hr:

Please enter the hour (0-23): 17

Please enter the minute (0-59): 46

Please enter Alarm -> second (0-59): 0

Please enter Alarm -> day of month (1-31): 14

Please enter Alarm -> day of week, 1 for Sunday (1-7): 1beforeSleep = 0 afterSleep = 0 nbWhile = 1

1Enter printTime Time as seconds since January 1, 1970 = 1494783825 Time as a basic string = Sun May 14 17:43:45 2017 Time as a custom formatted string = 05:43 PM

Exit printTime

Do you want to update time & calendar ? (0->no, 1->yes): Enter in DS3231Int Exit of DS3231Int

please use

<<code>>
your code
<</code>>

when posting code to that it remains readable

posted by Andy A 15 May 2017
Be the first to answer this question.