Firmware for the Software 3D Accelerometer Tester v1.1 or above

Dependencies:   MMA7660FC MODSERIAL mbed

I wrote a C# software that test the principal characteristics of this accelerometer MMA7660FC.


The software is here: 3D Accelerometer Tester v1.1
Is required Microsoft .NET Framework 3.5 or above.


This is the pins assignment:

MMA7660 pinsMbed pins
1 - SCLP10 - SCL
2 - SDAP9 - SDA
3 - VccVout - 3.3V
4 - GNDGND
5 - INTP6

NOTE: The I2C bus is already connected to pull-up resistor.


Some screens:

/media/uploads/edodm85/acc_img1.jpg

First you must set the Serial Port and press the button "Connect".
Then you can read the Sensor data (G acc and Orientation) manually pressing the button "Read DATA" or triggered by interrupt if you enabled in the second tab the checkbox "G Interrup Enable".
The red ball changes when the checkbox "SHAKE enable" is enabled.


/media/uploads/edodm85/acc_img2.jpg

In this screen you can set and read the registers manually or you can set easy the sample rate, the Shake Interrupt or the G Interrupt.


/media/uploads/edodm85/acc_img3.jpg

In this graph are plotted the G data read from the sensor.


For more infos visit this page.

Files at this revision

API Documentation at this revision

Comitter:
edodm85
Date:
Wed Aug 07 20:10:15 2013 +0000
Commit message:
First version

Changed in this revision

MMA7660FC.lib Show annotated file Show diff for this revision Revisions of this file
MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 1cef37031a2c MMA7660FC.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA7660FC.lib	Wed Aug 07 20:10:15 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/edodm85/code/MMA7660FC/#2cc4a317402d
diff -r 000000000000 -r 1cef37031a2c MODSERIAL.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL.lib	Wed Aug 07 20:10:15 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/MODSERIAL/#ae0408ebdd68
diff -r 000000000000 -r 1cef37031a2c main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Aug 07 20:10:15 2013 +0000
@@ -0,0 +1,113 @@
+/* Author: Edoardo De Marchi 
+ * Note: Firmware for the software 3D Accelerometer Tester v1.1
+ */
+ 
+#include "main.h"
+
+
+void INTSU()
+{
+    led4 = !led4;
+    bCheckINT = true;
+}
+
+void rxCallback(MODSERIAL_IRQ_INFO *q) 
+{
+     new_send = true;
+}
+
+
+int main() 
+{
+    
+    pc.baud(921600);
+    
+    pc.attach(&rxCallback, MODSERIAL::RxIrq);
+    INT.rise(&INTSU);
+    
+    MMA.init();    // Initialization 
+    
+    led1 = 1;
+    led4 = 0;
+           
+    while(1)
+    {    
+        if(new_send)
+        {
+            int i = 0;
+       
+            while(pc.readable())
+            {
+                word[i] = pc.getc();
+                i++;
+            }
+            parse_cmd(); 
+        }else
+        if(bCheckINT)
+        {            
+            if((MMA.read_reg(0x03) & 0x80) != 0)
+            {
+                pc.printf("SHAKE");
+            }else
+            if((MMA.read_reg(0x03) & 0x20) != 0)
+            {
+                pc.printf("TAPE");
+            }else    
+            {
+                strcpy(word,"read_data");
+                parse_cmd();
+            }  
+            bCheckINT = false;
+        }    
+        MMA.read_reg(0x00);       
+        wait_ms(50);
+        
+           
+    }
+}
+
+
+
+void parse_cmd(){
+            new_send = false;
+           
+            if(strcmp("reset", word) == 0)              
+            {
+                    mbed_reset();        
+            }else
+            if(strcmp("read_data", word) == 0)              
+            {
+                    pc.printf("x: %2d", MMA.read_x()+10);          // Print the X axis acceleration
+                    pc.printf("y: %2d", MMA.read_y()+10);          // Print the Y axis acceleration
+                    pc.printf("z: %2d", MMA.read_z()+10);          // Print the Z axis acceleration      
+            }else
+            if(strncmp("w_reg", word, 5) == 0)                 
+            {        
+                    int reg_addr = 0;                
+                    int reg_value = 0;
+                    char temp[3];
+                    strncpy(temp, &word[5], 3);  
+                    reg_addr = atoi(temp);
+                    memset(temp, 0, sizeof(temp));
+                    strncpy(temp, &word[8], 3); 
+                    reg_value = atoi(temp);                     
+                    MMA.write_reg(reg_addr, reg_value);
+                    
+                    memset(temp, 0, sizeof(temp));
+                    memset(word, 0, sizeof(word));
+            }else
+            if(strncmp("r_reg", word, 5) == 0)                 
+            {       
+            
+                    int reg_value = 0;
+                    char temp[3];
+                    strncpy(temp, &word[5], 3);  
+                    reg_value = atoi(temp);   
+                    pc.printf("%x", MMA.read_reg(reg_value));  
+                    
+                    memset(temp, 0, sizeof(temp));              
+                    memset(word, 0, sizeof(word));
+            }           
+            memset(word, 0, sizeof(word));            
+}
+
diff -r 000000000000 -r 1cef37031a2c main.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Wed Aug 07 20:10:15 2013 +0000
@@ -0,0 +1,26 @@
+#include "mbed.h"
+#include "MODSERIAL.h"
+#include "MMA7660FC.h"
+
+
+bool bCheckINT = false;
+bool new_send = false;
+
+
+#define ADDR_MMA7660 0x98                   // I2C SLAVE ADDR MMA7660FC
+
+MMA7660FC MMA(p9, p10, ADDR_MMA7660);       // sda, scl, Addr
+InterruptIn INT(p6);                        // INT pin of the device
+
+MODSERIAL pc(USBTX, USBRX);
+
+DigitalOut led1(LED1);
+DigitalOut led4(LED4);
+
+//RESET
+extern "C" void mbed_reset();
+
+//Serial
+char word[25];
+
+void parse_cmd();
\ No newline at end of file
diff -r 000000000000 -r 1cef37031a2c mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Aug 07 20:10:15 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17
\ No newline at end of file