The write...read pattern seems right. If you check out the libraries for some of the existing modules you'll see it's done in that way (http://www.espruino.com/I2C#using-i2c then you can usually go to a page a find a link to the module there). For instance in http://www.espruino.com/modules/VL53L0X.js there are two functions r and w:
What you might be missing is some chips only read properly if you do an I2C write and read without something called a "stop" between. You can force that my changing the address var to an object as in: http://www.espruino.com/Reference#l_I2C_writeTo
In your case maybe:
this.i2c.writeTo({address:this.MMA8451_ADDR, stop:false}, this.MMA8451_REG_OUT_X_MSB);
let buffer = this.i2c.readFrom(this.MMA8451_ADDR, 7);
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
The write...read pattern seems right. If you check out the libraries for some of the existing modules you'll see it's done in that way (http://www.espruino.com/I2C#using-i2c then you can usually go to a page a find a link to the module there). For instance in http://www.espruino.com/modules/VL53L0X.js there are two functions
r
andw
:What you might be missing is some chips only read properly if you do an I2C write and read without something called a "stop" between. You can force that my changing the address var to an object as in: http://www.espruino.com/Reference#l_I2C_writeTo
In your case maybe: