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.

Committer:
edodm85
Date:
Wed Aug 07 20:10:15 2013 +0000
Revision:
0:1cef37031a2c
First version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
edodm85 0:1cef37031a2c 1 /* Author: Edoardo De Marchi
edodm85 0:1cef37031a2c 2 * Note: Firmware for the software 3D Accelerometer Tester v1.1
edodm85 0:1cef37031a2c 3 */
edodm85 0:1cef37031a2c 4
edodm85 0:1cef37031a2c 5 #include "main.h"
edodm85 0:1cef37031a2c 6
edodm85 0:1cef37031a2c 7
edodm85 0:1cef37031a2c 8 void INTSU()
edodm85 0:1cef37031a2c 9 {
edodm85 0:1cef37031a2c 10 led4 = !led4;
edodm85 0:1cef37031a2c 11 bCheckINT = true;
edodm85 0:1cef37031a2c 12 }
edodm85 0:1cef37031a2c 13
edodm85 0:1cef37031a2c 14 void rxCallback(MODSERIAL_IRQ_INFO *q)
edodm85 0:1cef37031a2c 15 {
edodm85 0:1cef37031a2c 16 new_send = true;
edodm85 0:1cef37031a2c 17 }
edodm85 0:1cef37031a2c 18
edodm85 0:1cef37031a2c 19
edodm85 0:1cef37031a2c 20 int main()
edodm85 0:1cef37031a2c 21 {
edodm85 0:1cef37031a2c 22
edodm85 0:1cef37031a2c 23 pc.baud(921600);
edodm85 0:1cef37031a2c 24
edodm85 0:1cef37031a2c 25 pc.attach(&rxCallback, MODSERIAL::RxIrq);
edodm85 0:1cef37031a2c 26 INT.rise(&INTSU);
edodm85 0:1cef37031a2c 27
edodm85 0:1cef37031a2c 28 MMA.init(); // Initialization
edodm85 0:1cef37031a2c 29
edodm85 0:1cef37031a2c 30 led1 = 1;
edodm85 0:1cef37031a2c 31 led4 = 0;
edodm85 0:1cef37031a2c 32
edodm85 0:1cef37031a2c 33 while(1)
edodm85 0:1cef37031a2c 34 {
edodm85 0:1cef37031a2c 35 if(new_send)
edodm85 0:1cef37031a2c 36 {
edodm85 0:1cef37031a2c 37 int i = 0;
edodm85 0:1cef37031a2c 38
edodm85 0:1cef37031a2c 39 while(pc.readable())
edodm85 0:1cef37031a2c 40 {
edodm85 0:1cef37031a2c 41 word[i] = pc.getc();
edodm85 0:1cef37031a2c 42 i++;
edodm85 0:1cef37031a2c 43 }
edodm85 0:1cef37031a2c 44 parse_cmd();
edodm85 0:1cef37031a2c 45 }else
edodm85 0:1cef37031a2c 46 if(bCheckINT)
edodm85 0:1cef37031a2c 47 {
edodm85 0:1cef37031a2c 48 if((MMA.read_reg(0x03) & 0x80) != 0)
edodm85 0:1cef37031a2c 49 {
edodm85 0:1cef37031a2c 50 pc.printf("SHAKE");
edodm85 0:1cef37031a2c 51 }else
edodm85 0:1cef37031a2c 52 if((MMA.read_reg(0x03) & 0x20) != 0)
edodm85 0:1cef37031a2c 53 {
edodm85 0:1cef37031a2c 54 pc.printf("TAPE");
edodm85 0:1cef37031a2c 55 }else
edodm85 0:1cef37031a2c 56 {
edodm85 0:1cef37031a2c 57 strcpy(word,"read_data");
edodm85 0:1cef37031a2c 58 parse_cmd();
edodm85 0:1cef37031a2c 59 }
edodm85 0:1cef37031a2c 60 bCheckINT = false;
edodm85 0:1cef37031a2c 61 }
edodm85 0:1cef37031a2c 62 MMA.read_reg(0x00);
edodm85 0:1cef37031a2c 63 wait_ms(50);
edodm85 0:1cef37031a2c 64
edodm85 0:1cef37031a2c 65
edodm85 0:1cef37031a2c 66 }
edodm85 0:1cef37031a2c 67 }
edodm85 0:1cef37031a2c 68
edodm85 0:1cef37031a2c 69
edodm85 0:1cef37031a2c 70
edodm85 0:1cef37031a2c 71 void parse_cmd(){
edodm85 0:1cef37031a2c 72 new_send = false;
edodm85 0:1cef37031a2c 73
edodm85 0:1cef37031a2c 74 if(strcmp("reset", word) == 0)
edodm85 0:1cef37031a2c 75 {
edodm85 0:1cef37031a2c 76 mbed_reset();
edodm85 0:1cef37031a2c 77 }else
edodm85 0:1cef37031a2c 78 if(strcmp("read_data", word) == 0)
edodm85 0:1cef37031a2c 79 {
edodm85 0:1cef37031a2c 80 pc.printf("x: %2d", MMA.read_x()+10); // Print the X axis acceleration
edodm85 0:1cef37031a2c 81 pc.printf("y: %2d", MMA.read_y()+10); // Print the Y axis acceleration
edodm85 0:1cef37031a2c 82 pc.printf("z: %2d", MMA.read_z()+10); // Print the Z axis acceleration
edodm85 0:1cef37031a2c 83 }else
edodm85 0:1cef37031a2c 84 if(strncmp("w_reg", word, 5) == 0)
edodm85 0:1cef37031a2c 85 {
edodm85 0:1cef37031a2c 86 int reg_addr = 0;
edodm85 0:1cef37031a2c 87 int reg_value = 0;
edodm85 0:1cef37031a2c 88 char temp[3];
edodm85 0:1cef37031a2c 89 strncpy(temp, &word[5], 3);
edodm85 0:1cef37031a2c 90 reg_addr = atoi(temp);
edodm85 0:1cef37031a2c 91 memset(temp, 0, sizeof(temp));
edodm85 0:1cef37031a2c 92 strncpy(temp, &word[8], 3);
edodm85 0:1cef37031a2c 93 reg_value = atoi(temp);
edodm85 0:1cef37031a2c 94 MMA.write_reg(reg_addr, reg_value);
edodm85 0:1cef37031a2c 95
edodm85 0:1cef37031a2c 96 memset(temp, 0, sizeof(temp));
edodm85 0:1cef37031a2c 97 memset(word, 0, sizeof(word));
edodm85 0:1cef37031a2c 98 }else
edodm85 0:1cef37031a2c 99 if(strncmp("r_reg", word, 5) == 0)
edodm85 0:1cef37031a2c 100 {
edodm85 0:1cef37031a2c 101
edodm85 0:1cef37031a2c 102 int reg_value = 0;
edodm85 0:1cef37031a2c 103 char temp[3];
edodm85 0:1cef37031a2c 104 strncpy(temp, &word[5], 3);
edodm85 0:1cef37031a2c 105 reg_value = atoi(temp);
edodm85 0:1cef37031a2c 106 pc.printf("%x", MMA.read_reg(reg_value));
edodm85 0:1cef37031a2c 107
edodm85 0:1cef37031a2c 108 memset(temp, 0, sizeof(temp));
edodm85 0:1cef37031a2c 109 memset(word, 0, sizeof(word));
edodm85 0:1cef37031a2c 110 }
edodm85 0:1cef37031a2c 111 memset(word, 0, sizeof(word));
edodm85 0:1cef37031a2c 112 }
edodm85 0:1cef37031a2c 113