[riot-notifications] [RIOT-OS/RIOT] drivers: add driver for FXOS8700 3-axis accelerometer/magnetometer (#8978)

Joakim NohlgÄrd notifications at github.com
Mon Apr 23 12:09:20 CEST 2018


gebart requested changes on this pull request.

I found the source of my problems. Negative values of acceleration are not handled correctly, see my comment below regarding the bit shift

> +    uint8_t data[12];
+    uint8_t ready = 0;
+
+    if (fxos8700_set_active(dev)) {
+        return FXOS8700_BUSERR;
+    }
+
+    while (!(ready & 0x08)) {
+        fxos8700_read_regs(dev, FXOS8700_REG__STATUS, &ready, 1);
+    }
+    while (!(ready & 0x08)) {
+        fxos8700_read_regs(dev, FXOS8700_REG_M_DR_STATUS, &ready, 1);
+    }
+
+    /* Read all data at once */
+    if (fxos8700_read_regs(dev, FXOS8700_REG_OUT_X_MSB, &data[0], 12)) {

change magic `12` into sizeof something or a macro definition.

> +    }
+
+    /* Read all data at once */
+    if (fxos8700_read_regs(dev, FXOS8700_REG_OUT_X_MSB, &data[0], 12)) {
+        return FXOS8700_BUSERR;
+    }
+
+    if (fxos8700_set_idle(dev)) {
+        return FXOS8700_BUSERR;
+    }
+
+    /* Read accelerometer */
+    if (acc) {
+        int32_t acc_raw_x = (int32_t) ((data[0] << 6) | (data[1] >> 2));
+        int32_t acc_raw_y = (int32_t) ((data[2] << 6) | (data[3] >> 2));
+        int32_t acc_raw_z = (int32_t) ((data[4] << 6) | (data[5] >> 2));

the shift of 6 loses the sign bit

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/8978#pullrequestreview-114055090
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20180423/45c4cd2b/attachment.html>


More information about the notifications mailing list