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: mbed
Fork of ROHM-DragonFly-MultiSensorShield_Interface by
Diff: main.cpp
- Revision:
- 3:e2e8d92e5fcd
- Parent:
- 2:0c50ce4d9d04
- Child:
- 4:8be5ec736893
diff -r 0c50ce4d9d04 -r e2e8d92e5fcd main.cpp
--- a/main.cpp Wed Sep 23 22:18:55 2015 +0000
+++ b/main.cpp Wed Sep 23 23:02:58 2015 +0000
@@ -1,10 +1,14 @@
#include "mbed.h"
-#define LM75_REG_TEMP (0xC6u) // Temperature Register
-#define LM75_REG_CONF (0x41u) // Configuration Register
-#define LM75_ADDR (0x38u) // LM75 address
-#define RPR0521RS_ProxLSB (0x41u)
-
+#define RPR0521_MODE_CONT_CONTENT (0xC6u) // Temperature Register
+#define RPR0521_MODE_CONT (0x41u) // Configuration Register
+#define BH1745_SAD (0x38u) // LM75 address
+#define BH1745_MODE_CONTROL1 (0x41u)
+#define BH1745_MODE_CONTROL2 (0x42u)
+#define BH1745_MODE_CONTROL3 (0x43u)
+#define BH1745_PERSISTANT (0x61u)
+#define BH1745_CLEAR_LSB (0x50u)
+
I2C i2c(I2C_SDA, I2C_SCL);
DigitalOut myled(LED1);
@@ -63,11 +67,40 @@
- Thermostat mode Interrupt
- Fault tolerance: 0
*/
+
+ data_write[0] = BH1745_PERSISTANT;
+ data_write[1] = 0x03u;
+ int status = i2c.write(BH1745_SAD, data_write, 2, 0);
+ if (status != 0) { // Error
+ while (1) {
+ myled = !myled;
+ wait(0.7);
+ }
+ }
- data_write[0] = LM75_REG_CONF;
- data_write[1] = LM75_REG_TEMP;
- int status = i2c.write(LM75_ADDR, data_write, 2, 0);
-
+ data_write[0] = BH1745_MODE_CONTROL1;
+ data_write[1] = 0x00u;
+ status = i2c.write(BH1745_SAD, data_write, 2, 0);
+ if (status != 0) { // Error
+ while (1) {
+ myled = !myled;
+ wait(0.7);
+ }
+ }
+
+ data_write[0] = BH1745_MODE_CONTROL2;
+ data_write[1] = 0x92u;
+ status = i2c.write(BH1745_SAD, data_write, 2, 0);
+ if (status != 0) { // Error
+ while (1) {
+ myled = !myled;
+ wait(0.7);
+ }
+ }
+
+ data_write[0] = BH1745_MODE_CONTROL3;
+ data_write[1] = 0x02u;
+ status = i2c.write(BH1745_SAD, data_write, 2, 0);
if (status != 0) { // Error
while (1) {
myled = !myled;
@@ -79,9 +112,9 @@
while (1) {
// I2C Routines *******************************************************
// Read temperature register
- data_write[0] = RPR0521RS_ProxLSB;
- i2c.write(LM75_ADDR, data_write, 1, 1); // no stop
- i2c.read(LM75_ADDR, data_read, 1, 0);
+ data_write[0] = BH1745_CLEAR_LSB;
+ i2c.write(BH1745_SAD, data_write, 1, 1); // no stop
+ i2c.read(BH1745_SAD, data_read, 1, 0);
// Calculate temperature value in Celcius
int tempval = (int)data_read[0];
