@@ -1406,14 +1406,16 @@ void peripheralPollHandler() {
1406
1406
data_temp [1 ] = buf [2 ] | (buf [3 ]<<8 );
1407
1407
data_temp [2 ] = buf [4 ] | (buf [5 ]<<8 );
1408
1408
// adjust range to be in uTesla (0.8 scaling according to datasheet)
1409
+ // NOTE: it is possible to read calibration values from OTP and apply those but maybe we don't care
1409
1410
mag .x = ((32768 - data_temp [0 ]) * 205 ) >> 8 ; // * 0.8
1410
1411
mag .y = ((data_temp [2 ] - data_temp [1 ]) * 205 ) >> 8 ; // * 0.8
1411
1412
mag .z = ((65536 - (data_temp [1 ] + data_temp [2 ])) * 276 ) >> 8 ; // * 1.35 * 0.8 (Z axis is scaled differently)
1412
1413
// TODO: there are calibration registers
1413
1414
newReading = true;
1415
+ // TODO: should we call SET every so often to keep the sensor happy? example code does.
1416
+ /* Write 0x01 to register 0x08, set TM_M bit high - kick off new reading */
1417
+ jsi2cWriteReg (MAG_I2C , MAG_MMC36X0_ADDR , 0x08 /*MMC36X0_REG_CTRL0*/ , 0x01 /*MMC36X0_CMD_TM_M*/ );
1414
1418
}
1415
- /* Write 0x01 to register 0x08, set TM_M bit high - kick off new reading */
1416
- jsi2cWriteReg (MAG_I2C , MAG_MMC36X0_ADDR , 0x08 /*MMC36X0_REG_CTRL0*/ , 0x01 /*MMC36X0_CMD_TM_M*/ );
1417
1419
}
1418
1420
#endif
1419
1421
if (newReading ) {
@@ -3275,23 +3277,23 @@ bool jswrap_banglejs_setCompassPower(bool isOn, JsVar *appId) {
3275
3277
#endif
3276
3278
#ifdef MAG_DEVICE_MMC36X0
3277
3279
if (MAG_DEVICE_MMC36X0_EN ) {
3280
+ // NOTE: What follows is based on MMC36X0 example code but *isn't*in the datasheet
3278
3281
/* Change the SET/RESET pulse width */
3279
3282
/* Write 0x00 to register 0x0A, set ULP_SEL bit low */
3280
- jsi2cWriteReg (MAG_I2C , MAG_MMC36X0_ADDR , 0x0A /*MMC36X0_REG_CTRL2*/ , 0x00 /*MMC36X0_CMD_OTP_NACT*/ );
3281
-
3283
+ //jsi2cWriteReg(MAG_I2C, MAG_MMC36X0_ADDR, 0x0A/*MMC36X0_REG_CTRL2*/, 0x00/*MMC36X0_CMD_OTP_NACT*/);
3282
3284
/* Write 0xE1 to register 0x0F, write password */
3283
- jsi2cWriteReg (MAG_I2C , MAG_MMC36X0_ADDR , 0x0F /*MMC36X0_REG_PASSWORD*/ , 0xE1 /*MMC36X0_CMD_PASSWORD*/ );
3284
-
3285
+ //jsi2cWriteReg(MAG_I2C, MAG_MMC36X0_ADDR, 0x0F/*MMC36X0_REG_PASSWORD*/, 0xE1/*MMC36X0_CMD_PASSWORD*/);
3285
3286
/* Read and write register 0x20, set SR_PW<1:0> = 00 = 1us */
3286
- unsigned char reg ;
3287
- jsi2cReadReg (MAG_I2C , MAG_MMC36X0_ADDR , 0x20 /*MMC36X0_REG_SR_PWIDTH*/ , 1 , & reg );
3288
- reg = reg & 0xE7 ;
3289
- jsi2cWriteReg (MAG_I2C , MAG_MMC36X0_ADDR , 0x20 /*MMC36X0_REG_SR_PWIDTH*/ , reg );
3287
+ //unsigned char reg;
3288
+ //jsi2cReadReg(MAG_I2C, MAG_MMC36X0_ADDR, 0x20/*MMC36X0_REG_SR_PWIDTH*/, 1, ®);
3289
+ //reg = reg & 0xE7;
3290
+ //jsi2cWriteReg(MAG_I2C, MAG_MMC36X0_ADDR, 0x20/*MMC36X0_REG_SR_PWIDTH*/, reg);
3291
+
3290
3292
/* SET operation when using dual supply - Write 0x08 to register 0x08, set SET bit high */
3291
3293
jsi2cWriteReg (MAG_I2C , MAG_MMC36X0_ADDR , 0x08 /*MMC36X0_REG_CTRL0*/ , 0x08 /*MMC36X0_CMD_SET*/ );
3292
- /* Write register 0x09, Set BW<1:0> = 0x00, 0x01, 0x02, or 0x03 */
3294
+ /* Set highest accuracy mode, Write register 0x09, Set BW<1:0> = 0x00, 0x01, 0x02, or 0x03 */
3293
3295
jsi2cWriteReg (MAG_I2C , MAG_MMC36X0_ADDR , 0x09 /*MMC36X0_REG_CTRL1*/ , 0 /*MMC36X0_CMD_100HZ*/ );
3294
- /* Enable sensor when from pown down mode to normal mode, Write 0x01 to register 0x08, set TM_M bit high */
3296
+ /* Enable sensor when from pown down mode to normal mode, Write 0x01 to register 0x08, set TM_M bit high to kick off a reading */
3295
3297
jsi2cWriteReg (MAG_I2C , MAG_MMC36X0_ADDR , 0x08 /*MMC36X0_REG_CTRL0*/ , 1 /*MMC36X0_CMD_TM_M*/ );
3296
3298
nrf_delay_ms (10 );
3297
3299
}
0 commit comments