Class Module for MMA845x I2C Accelerometer.
Dependents: mDotEVBM2X MTDOT-EVBDemo-DRH MTDOT-BOX-EVB-Factory-Firmware-LIB-108 MTDOT-UDKDemo_Senet ... more
Fork of MMA845x by
Revision 5:d662a7003b6f, committed 2018-01-31
- Comitter:
- Evan Hosseini
- Date:
- Wed Jan 31 10:02:14 2018 -0600
- Parent:
- 4:4ff1650da84c
- Commit message:
- Make driver thread safe by making i2c read transactions atomic
Changed in this revision
| MMA845x.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/MMA845x.cpp Mon Oct 17 08:38:38 2016 -0500
+++ b/MMA845x.cpp Wed Jan 31 10:02:14 2018 -0600
@@ -50,7 +50,6 @@
uint8_t i = 0;
char reg_val[1];
- _i2c->frequency(100000);
_who_am_i = 0x00;
// Reset all registers to POR values
@@ -290,8 +289,8 @@
result |= _i2c->write(_i2c_addr, buf, 2);
- if(result != 0) {
- debug("MMA845x:writeRegister failed r-%d\n\r",result);
+ if (result != 0) {
+ debug("MMA845x::writeRegister failed r-%d\n\r",result);
}
return result;
@@ -303,18 +302,23 @@
char reg_out[1];
reg_out[0] = reg;
+ _i2c->lock();
+
+ // MMA8451Q expects a repeated start from the master
result |= _i2c->write(_i2c_addr,reg_out,1,true);
- if(result != 0) {
+ if (result != 0) {
debug("MMA845x::readRegister failed write r- %d\n\r", result);
- return result;
+ goto exit;
}
result |= _i2c->read(_i2c_addr,data,count,false);
- if(result != 0) {
+ if (result != 0) {
debug("MMA845x::readRegister failed read r-%d\n\r",result);
}
+exit:
+ _i2c->unlock();
return result;
}
