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/

Revision:
7:cedbf234a089
Parent:
6:a3238e93f694
Child:
8:7e42f8dc42a2
--- a/main.cpp	Wed Dec 18 09:24:58 2019 +0000
+++ b/main.cpp	Thu Dec 19 01:43:46 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  18th, 2019
+ *      Revised:    December  19th, 2019
  */
 
 //  Include --------------------------------------------------------------------
@@ -16,15 +16,11 @@
 #include "RX8025NB.h"
 #include "BME280_SPI.h"
 #include "MB85RSxx_SPI.h"
-#include "nRF51_lowpwr.h"
 
 //  Definition -----------------------------------------------------------------
 #define KEPP_SLEEP_TIME 1               // 0= continuos mode (every 10sec)           
-#define SLEEP_TIME      5               // Sleep 2 minutes
-#define FRAM_ID0        (0x04)          // Fijitsu 2Mbits(0x047f4803)
-#define FRAM_ID1        (0x7f)
-#define FRAM_ID2        (0x48)
-#define FRAM_ID3        (0x03)
+#define SLEEP_TIME      2               // Sleep 2 minutes
+#define FRAM_ID         (0x047f4803)    // Fijitsu 2Mbits
 
 //  Constructor ----------------------------------------------------------------
 DigitalOut  bme280_pwr(D9, 1);  // BME280 sensor power on
@@ -46,19 +42,9 @@
     
 //  ROM / Constant data --------------------------------------------------------
 const char *const opngmsg0 =
-    "\r\n---------\r\n Compiled on " __DATE__ " " __TIME__ " (UTC)\r\n";
+    "\r\n---------\r\nCompiled on " __DATE__ " " __TIME__ " (UTC)\r\n";
 const char *const opngmsg1 =
-    " Project: TYBLE16_simple_data_logger  by Kenji Arai\r\n";
-
-const nRF51_LOWPWR_TypeDef  lowpwr_table = 
-    { false, // VCOM
-      false, // UART
-      false,  // I2C
-      false, // SPI
-      false, // SPI Slave
-      false, // PWM
-      false  // ADC
-};
+    "Project: TYBLE16_simple_data_logger  by Kenji Arai\r\n";
  
 //  Function prototypes --------------------------------------------------------
 static void rtc_interrupt(void);
@@ -73,31 +59,35 @@
     char buf[64];               // data buffer for text
     time_t seconds;
 
-    ThisThread::sleep_for(200);
+    ThisThread::sleep_for(100);
     pc.puts(opngmsg0);
     pc.puts(opngmsg1);
     // Check TYBLE-16 configuration
     cpu_sys();
     compile_condition();
     // Create constructor
-    // RX8025
-    RX8025 ex_rtc(I2C_SDA, I2C_SCL);    // RTC(RX8025) (Fixed address)
     // BM280
     BME280_SPI bme280(SPIS_PSELMOSI, SPIS_PSELMISO, SPIS_PSELSCK, P0_25);
     // FRAM
     MB85RSxx_SPI fram(SPIS_PSELMOSI, SPIS_PSELMISO, SPIS_PSELSCK, P0_6);
     fram.read_device_id(fram_id);
-#if 0
-    if (fram_id == FRAM_ID) {
+    uint32_t id = 0, num = 24;
+    for (uint32_t i = 0; i < 4; i++) {
+        id += fram_id[i] << num;
+        num -= 8;
+    }
+    pc.printf("FRAM ID=0x%08x", id);
+    if (id == FRAM_ID) {
         fram_ready = true;
     }
-    pc.printf("FRAM ID = 0x%08x\r\n", fram_id);
-#else
-    for (uint32_t i = 0; i < 4; i++) {
-        pc.printf("FRAM ID = 0x%08x\r\n", fram_id[i]);
+    if (fram_ready == true){
+        pc.printf("(looks like Fujitsu MB85RS2M)\r\n");
+    } else {
+        pc.printf("(unknown device)\r\n");
     }
-#endif
-    // RTC related preparation
+    // RX8025
+    RX8025 ex_rtc(I2C_SDA, I2C_SCL);    // RTC(RX8025) (Fixed address)
+    ThisThread::sleep_for(500);
     ex_rtc.clear_alarmD_INTA();
     w_check_rtc_time(ex_rtc);
     int32_t count = 3;
@@ -123,16 +113,17 @@
             break;
         }
     }
-    dtlog_data_pack();          // Preparation for FRAM
+    dtlog_data_pack();          // Data preparation for FRAM
     dtlog_one_write(fram);      // Write data to FRAM
 #if KEPP_SLEEP_TIME
     rtc_irq.fall(&rtc_interrupt);
     uint16_t sleeping_time = SLEEP_TIME;
+    pc.printf("Enter sleep mode and wake up after %d minutes\r\n",
+              sleeping_time);
     ex_rtc.set_next_alarmD_INTA(sleeping_time);
     //----- SLEEP --------------------------------------------------------------
     bme280_pwr = 0;
     fram_pwr = 0;
-    LowPwr set_lowpwr(&lowpwr_table);
     ThisThread::sleep_for((sleeping_time) * 60 * 1000 + 10000);
     system_reset();
 #else