An example demonstrating the usage of the default FXOS8700CQ firmware configuration by Thomas Murphy. Uses interrupts to control flow and to cue access to the peripheral.

Dependencies:   FXOS8700CQ-AccOnly50hz mbed

Fork of fxos8700cq_example by Thomas Murphy

Files at this revision

API Documentation at this revision

Comitter:
julianhigginson
Date:
Fri Feb 05 00:35:44 2016 +0000
Parent:
0:6c6060a8a2f6
Commit message:
working, approximately.

Changed in this revision

FXOS8700CQ-AccOnly50hz.lib Show annotated file Show diff for this revision Revisions of this file
FXOS8700CQ.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 6c6060a8a2f6 -r d006ce66f663 FXOS8700CQ-AccOnly50hz.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FXOS8700CQ-AccOnly50hz.lib	Fri Feb 05 00:35:44 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/julianhigginson/code/FXOS8700CQ-AccOnly50hz/#f79ab691a47b
diff -r 6c6060a8a2f6 -r d006ce66f663 FXOS8700CQ.lib
--- a/FXOS8700CQ.lib	Wed May 28 17:32:41 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/trm/code/FXOS8700CQ/#4c2f8a3549a9
diff -r 6c6060a8a2f6 -r d006ce66f663 main.cpp
--- a/main.cpp	Wed May 28 17:32:41 2014 +0000
+++ b/main.cpp	Fri Feb 05 00:35:44 2016 +0000
@@ -13,9 +13,9 @@
 DigitalOut red(LED_RED); // completed/error ligt
 
 Timer t; // Microsecond timer, 32 bit int, maximum count of ~30 minutes
-InterruptIn fxos_int1(PTC6); // unused, common with SW2 on FRDM-K64F
+//InterruptIn fxos_int1(PTC6); // unused, common with SW2 on FRDM-K64F
 InterruptIn fxos_int2(PTC13); // should just be the Data-Ready interrupt
-InterruptIn start_sw(PTA4); // switch SW3
+//InterruptIn start_sw(PTA4); // switch SW3
 
 // Interrupt status flags and data
 bool fxos_int1_triggered = false;
@@ -27,28 +27,24 @@
 SRAWDATA accel_data;
 SRAWDATA magn_data;
 
-void trigger_fxos_int1(void)
+void print_reading()
 {
-    fxos_int1_triggered = true;
+//    pc.printf("%d A X:%5d,Y:%5d,Z:%5d   M X:%5d,Y:%5d,Z:%5d\r\n",
+//              us_ellapsed,
+//             accel_data.x, accel_data.y, accel_data.z,
+//              magn_data.x, magn_data.y, magn_data.z);
+    pc.printf("%d A X:%5d,Y:%5d,Z:%5d \r\n",
+    //pc.printf("%d A X:%5x,Y:%5x,Z:%5x \r\n",
+              us_ellapsed/1000,
+              accel_data.x, accel_data.y, accel_data.z);
 }
 
+
 void trigger_fxos_int2(void)
 {
-    fxos_int2_triggered = true;
     us_ellapsed = t.read_us();
-}
-
-void trigger_start_sw(void)
-{
-    start_sw_triggered = true;
-}
-
-void print_reading()
-{
-    pc.printf("%d A X:%5d,Y:%5d,Z:%5d   M X:%5d,Y:%5d,Z:%5d\r\n",
-              us_ellapsed,
-              accel_data.x, accel_data.y, accel_data.z,
-              magn_data.x, magn_data.y, magn_data.z);
+    fxos.get_data(&accel_data);
+    print_reading(); 
 }
 
 int main(void)
@@ -63,61 +59,36 @@
     blue.write(1);
 
     // Diagnostic printing of the FXOS WHOAMI register value
-    printf("\r\n\nFXOS8700Q Who Am I= %X\r\n", fxos.get_whoami());
+    pc.printf("\r\n\nFXOS8700Q Who Am I= %X\r\n", fxos.get_whoami());
 
     // Iterrupt for active-low interrupt line from FXOS
     // Configured with only one interrupt on INT2 signaling Data-Ready
     fxos_int2.fall(&trigger_fxos_int2);
+
+    pc.printf("Started data collection. Accelerometer at max %dg.\r\n", fxos.get_accel_scale());
+
+    pc.printf("FXOS8700CQ_CTRL_REG1    0x%02x\r\n", fxos.read_single_reg(FXOS8700CQ_CTRL_REG1));
+    pc.printf("FXOS8700CQ_CTRL_REG2    0x%02x\r\n", fxos.read_single_reg(FXOS8700CQ_CTRL_REG2));
+    pc.printf("FXOS8700CQ_CTRL_REG3    0x%02x\r\n", fxos.read_single_reg(FXOS8700CQ_CTRL_REG3));
+    pc.printf("FXOS8700CQ_CTRL_REG4    0x%02x\r\n", fxos.read_single_reg(FXOS8700CQ_CTRL_REG4));
+    pc.printf("FXOS8700CQ_CTRL_REG5    0x%02x\r\n", fxos.read_single_reg(FXOS8700CQ_CTRL_REG5));
+
+    pc.printf("FXOS8700CQ_M_CTRL_REG1  0x%02x\r\n", fxos.read_single_reg(FXOS8700CQ_M_CTRL_REG1));
+    pc.printf("FXOS8700CQ_M_CTRL_REG2  0x%02x\r\n", fxos.read_single_reg(FXOS8700CQ_M_CTRL_REG2));
+    pc.printf("FXOS8700CQ_M_CTRL_REG3  0x%02x\r\n", fxos.read_single_reg(FXOS8700CQ_M_CTRL_REG3));
+
+    pc.printf("FXOS8700CQ_XYZ_DATA_CFG 0x%02x\r\n", fxos.read_single_reg(FXOS8700CQ_XYZ_DATA_CFG));
+
+
+
+    fxos.get_data(&accel_data); // clear interrupt from device
+
+    t.start(); // start timer and enter collection loop
+
     fxos.enable();
 
-    // Interrupt for SW3 button-down state
-    start_sw.mode(PullUp); // Since the FRDM-K64F doesn't have its SW2/SW3 pull-ups populated
-    start_sw.fall(&trigger_start_sw);
-
-    green.write(0); // ready-green on
-
-    // Example data printing
-    fxos.get_data(&accel_data, &magn_data);
-    print_reading();
-
-    pc.printf("Waiting for data collection trigger on SW3\r\n");
-
-    while(true) {
-        if(start_sw_triggered) {
-            break;
-        }
-        wait_ms(50); // just to slow the loop, fast enough for UX
-    }
-
-    green.write(1); // ready-green off
-    blue.write(0); // working-blue on
-
-   pc.printf("Started data collection. Accelerometer at max %dg.\r\n",
-   fxos.get_accel_scale());
-
-    fxos.get_data(&accel_data, &magn_data); // clear interrupt from device
-    fxos_int2_triggered = false; // un-trigger
-
-    t.start(); // start timer and enter collection loop
-    while (t.read_ms() <= DATA_RECORD_TIME_MS) {
-
-        if(fxos_int2_triggered) {
-            fxos_int2_triggered = false; // un-trigger
-            fxos.get_data(&accel_data, &magn_data);
-            print_reading(); // outpouring of data !!
-        }
-
-        // Continuous polling of interrupt status is not efficient, but...
+    while(1) {
         wait_us(500); // 1/10th the period of the 200Hz sample rate
     }
 
-    blue.write(1); // working-blue off
-    red.write(0); // complete-red on
-
-    pc.printf("Done. Reset to repeat.\r\n");
-
-    while(true) {
-        pc.putc('.'); // idle dots
-        wait(1.0);
-    }
 }
\ No newline at end of file