Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: APDS_9960 LPS22HB LSM9DS1 HTS221
Diff: common.cpp
- Revision:
- 0:f1a10797d9f6
diff -r 000000000000 -r f1a10797d9f6 common.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/common.cpp Fri Feb 07 01:21:16 2020 +0000
@@ -0,0 +1,123 @@
+/*
+ * Nano 33 BLE Sense
+ * Arudiono nRF52840 module
+ * Common functions
+ *
+ * Copyright (c) 2020 Kenji Arai / JH1PJL
+ * http://www7b.biglobe.ne.jp/~kenjia/
+ * https://os.mbed.com/users/kenjiArai/
+ * Started: January 22nd, 2020
+ * Revised: Feburary 5th, 2020
+ *
+ */
+
+// Pre-selection --------------------------------------------------------------
+#include "select_example.h"
+//#define USE_COMMON_FUNCTION
+#ifdef USE_COMMON_FUNCTION
+
+// Include --------------------------------------------------------------------
+#include "mbed.h"
+#include "nano33blesense_iodef.h"
+#include "USBSerial.h"
+#include "LPS22HB.h"
+#include "LSM9DS1.h"
+#include "HTS221.h"
+#include "glibr.h"
+
+// Definition -----------------------------------------------------------------
+
+// Constructor ----------------------------------------------------------------
+extern RawSerial pc;
+extern I2C i2c;
+
+// RAM ------------------------------------------------------------------------
+
+// ROM / Constant data --------------------------------------------------------
+
+// Function prototypes --------------------------------------------------------
+
+//------------------------------------------------------------------------------
+// Control Program
+//------------------------------------------------------------------------------
+void check_i2c_connected_devices(void)
+{
+ char dt[2];
+ int status;
+
+ // Check I2C line
+ i2c.frequency(400000);
+ dt[0] = 0;
+ pc.printf("check I2C device --> START\r\n");
+ for (uint8_t i = 0; i < 0x80; i++) {
+ int addr = i << 1;
+ status = i2c.write(addr, dt, 1, true);
+ if (status == 0) {
+ pc.printf("Get ACK form address = 0x%x\r\n", i);
+ }
+ }
+}
+
+void check_i2c_sensors(void)
+{
+ char dt[2];
+
+ // LSM9DS1
+ dt[0] = WHO_AM_I_XG;
+ int addr = LSM9DS1_AG_I2C_ADDR(1);
+ i2c.write(addr, dt, 1, true);
+ dt[0] = 0;
+ i2c.read(addr, dt, 1, false);
+ pc.printf("LSM9DS1_AG is ");
+ if (dt[0] != WHO_AM_I_AG_RSP) {
+ pc.printf("NOT ");
+ }
+ pc.printf("available -> 0x%x = 0x%x\r\n", addr >> 1, dt[0]);
+ dt[0] = WHO_AM_I_M;
+ addr = LSM9DS1_M_I2C_ADDR(1);
+ i2c.write(addr, dt, 1, true);
+ dt[0] = 0;
+ i2c.read(addr, dt, 1, false);
+ pc.printf("LSM9DS1_M is ");
+ if (dt[0] != WHO_AM_I_M_RSP) {
+ pc.printf("NOT ");
+ }
+ pc.printf("available -> 0x%x = 0x%x\r\n", addr >> 1, dt[0]);
+ // LPS22HB
+ dt[0] = LPS22HB_WHO_AM_I;
+ addr = LPS22HB_G_CHIP_ADDR;
+ i2c.write(addr, dt, 1, true);
+ dt[0] = 0;
+ i2c.read(addr, dt, 1, false);
+ pc.printf("LPS22HB is ");
+ if (dt[0] != I_AM_LPS22HB) {
+ pc.printf("NOT ");
+ }
+ pc.printf("available -> 0x%x = 0x%x\r\n", addr >> 1, dt[0]);
+ // HTS221
+ dt[0] = HTS221::HTS221_WHO_AM_I;
+ addr = HTS221::HTS221_ADDRESS;
+ i2c.write(addr, dt, 1, true);
+ dt[0] = 0;
+ i2c.read(addr, dt, 1, false);
+ pc.printf("HTS221 is ");
+ if (dt[0] != HTS221::WHO_AM_I_VALUE) {
+ pc.printf("NOT ");
+ }
+ pc.printf("available -> 0x%x = 0x%x\r\n", addr >> 1, dt[0]);
+ // APDS_9960
+ dt[0] = APDS9960_ID;
+ addr = APDS9960_I2C_ADDR << 1;
+ i2c.write(addr, dt, 1, true);
+ dt[0] = 0;
+ i2c.read(addr, dt, 1, false);
+ pc.printf("APDS_9960 is ");
+ if (dt[0] == APDS9960_ID_1 || dt[0] == APDS9960_ID_2) {
+ ;
+ } else {
+ pc.printf("NOT ");
+ }
+ pc.printf("available -> 0x%x = 0x%x\r\n", addr >> 1, dt[0]);
+}
+
+#endif // USE_COMMON_FUNCTION
\ No newline at end of file