1st working program

Dependencies:   mbed-os_TYBLE16 BME280_SPI RX8025NB nRF51_Vdd MB85RSxx_SPI

see /users/kenjiArai/notebook/tyble16-module-as-mbed-os-5-board-mbedlization/

Files at this revision

API Documentation at this revision

Comitter:
kenjiArai
Date:
Sun Dec 22 06:33:18 2019 +0000
Parent:
8:7e42f8dc42a2
Commit message:
reduce current consumption

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Dec 20 01:19:40 2019 +0000
+++ b/main.cpp	Sun Dec 22 06:33:18 2019 +0000
@@ -5,7 +5,7 @@
  *  http://www.page.sannet.ne.jp/kenjia/index.html
  *  https://os.mbed.com/users/kenjiArai/
  *      Created:    December  14th, 2019
- *      Revised:    December  20th, 2019
+ *      Revised:    December  22nd, 2019
  */
 
 //  Include --------------------------------------------------------------------
@@ -25,6 +25,8 @@
 //  Constructor ----------------------------------------------------------------
 DigitalOut  bme280_pwr(D9, 1);  // BME280 sensor power on
 DigitalOut  fram_pwr(D5, 1);    // FRAM power on
+DigitalInOut  x0(I2C_SDA, PIN_OUTPUT, PullUp, 1);    // I2C for dummy
+DigitalInOut  x1(I2C_SCL, PIN_OUTPUT, PullUp, 1);    // I2C for dummy
 InterruptIn rtc_irq(P0_2, PullUp);
 Serial      pc(USBTX, USBRX);
 nRF51_Vdd   vdd(3.6f, 1.6f, ONLY4VDD);
@@ -49,6 +51,7 @@
 //  Function prototypes --------------------------------------------------------
 static void rtc_interrupt(void);
 static void goto_standby(void);
+static void priparation_for_sleep(void);
 time_t w_check_rtc_time(RX8025 &ex_rtc);
 
 //------------------------------------------------------------------------------
@@ -59,7 +62,7 @@
     char buf[64];               // data buffer for text
     time_t seconds;
 
-    ThisThread::sleep_for(20);
+    // open message
     pc.puts(opngmsg0);
     pc.puts(opngmsg1);
     // Check TYBLE-16 configuration
@@ -87,7 +90,7 @@
     }
     // RX8025
     RX8025 ex_rtc(I2C_SDA, I2C_SCL);    // RTC(RX8025) (Fixed address)
-    ThisThread::sleep_for(100);
+    ThisThread::sleep_for(20);
     ex_rtc.clear_alarmD_INTA();
     w_check_rtc_time(ex_rtc);
     int32_t count = 3;
@@ -125,6 +128,22 @@
     // FRAM & BME280 power off
     bme280_pwr = 0;
     fram_pwr = 0;
+    priparation_for_sleep();
+    // Enter sleep mode
+    ThisThread::sleep_for((sleeping_time) * 60 * 1000 + 10000);
+    system_reset();
+#else
+    // FRAM & BME280 power off
+    bme280_pwr = 0;
+    fram_pwr = 0;
+    priparation_for_sleep();
+    ThisThread::sleep_for(8000);
+    system_reset();
+#endif
+}
+
+void priparation_for_sleep(void)
+{
     // SPI output keeps low
     DigitalOut p0(SPIS_PSELMOSI, 0);
     DigitalOut p1(SPIS_PSELSCK, 0);
@@ -133,25 +152,16 @@
     // SPI MISO sets pulldown
     DigitalIn  p4(SPIS_PSELMISO, PullDown);
     // Periperal power off
-    NRF_UART0->ENABLE           = 0;
-    NRF_UART0->POWER            = 0;
-    NRF_TWI1->ENABLE            = 0;
-    NRF_TWI1->POWER             = 0;
-    NRF_SPI0->ENABLE            = 0;
-    NRF_SPI0->POWER             = 0;
-    NRF_SPIS1->ENABLE            = 0;
-    NRF_SPIS1->POWER             = 0;
-    NRF_ADC->ENABLE             = 0;
-    NRF_ADC->POWER              = 0;
-    // Enter sleep mode
-    ThisThread::sleep_for((sleeping_time) * 60 * 1000 + 10000);
-    system_reset();
-#else
-    bme280_pwr = 0;
-    fram_pwr = 0;
-    ThisThread::sleep_for(8000);
-    system_reset();
-#endif
+    NRF_UART0->ENABLE = 0;
+    NRF_UART0->POWER  = 0;
+    NRF_TWI1->ENABLE  = 0;
+    NRF_TWI1->POWER   = 0;
+    NRF_SPI0->ENABLE  = 0;
+    NRF_SPI0->POWER   = 0;
+    NRF_SPIS1->ENABLE = 0;
+    NRF_SPIS1->POWER  = 0;
+    NRF_ADC->ENABLE   = 0;
+    NRF_ADC->POWER    = 0;
 }
 
 void rtc_interrupt(void)