
A test utility for mma8452
Revision 5:34fa5db89a3a, committed 2013-10-16
- Comitter:
- nherriot
- Date:
- Wed Oct 16 16:26:39 2013 +0000
- Parent:
- 4:489573e65d47
- Child:
- 6:94d7ca596f52
- Commit message:
- simplification on several methods
Changed in this revision
MMA8452.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 |
--- a/MMA8452.lib Wed Oct 16 14:12:28 2013 +0000 +++ b/MMA8452.lib Wed Oct 16 16:26:39 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/nherriot/code/MMA8452/#ffb0b1650ca2 +http://mbed.org/users/nherriot/code/MMA8452/#27aa3cd43234
--- a/main.cpp Wed Oct 16 14:12:28 2013 +0000 +++ b/main.cpp Wed Oct 16 16:26:39 2013 +0000 @@ -14,27 +14,24 @@ - - - - - - int main() { led1 = 0; led2 = 0; led3 = 0; - char cmd[6]; - char add[1]; - char init[2]; - add[0] = OUT_X_MSB; // x-axis register - init[0] = CTRL_REG_1; // control register 1 - init[1] = 0x01; // sets the accelerometer to active - int number=0; + char x_buffer[2]; // used to store a bit array from the x axis acclerometer char y_buffer[2]; // this represents the raw data value from the acclerometer char z_buffer[2]; // which is converted from 12bit to 16bit value 2s compliment. + x_buffer[0] = 0x00; + x_buffer[1] = 0x00; + y_buffer[0] = 0x00; + y_buffer[1] = 0x00; + z_buffer[0] = 0x00; + z_buffer[0] = 0x00; + + int deviceSystemMode(0); + // just playing with address values char mcu_address = 0x00; pc.printf("\nmcu_address is: 0x%x ", mcu_address); @@ -47,32 +44,20 @@ //init //set active mode pc.printf("\nWriting to master register\n"); + + int deviceStatus = 0; + if (accelerometer.get_Status(deviceStatus)==0) + { + pc.printf("\nGot the device Status - device status which is: 0x%x \n", deviceStatus); + } + else + { + pc.printf("\nFailed to get the device status. The id is set as: 0x%x ", deviceStatus); + } + for (int i=0;i<=50;i++) { - int deviceSystemMode= 0; - if (accelerometer.get_SystemMode(deviceSystemMode)==0) - { - pc.printf("\nGot the device System Mode - device system mode which is: 0x%x \n", deviceSystemMode); - } - else - { - pc.printf("\nFailed to get the device system mode. The id is set as: 0x%x ", deviceSystemMode); - - } - - int deviceStatus = 0; - if (accelerometer.get_Status(deviceStatus)==0) - { - pc.printf("\nGot the device Status - device status which is: 0x%x \n", deviceStatus); - } - else - { - pc.printf("\nFailed to get the device status. The id is set as: 0x%x ", deviceStatus); - - } - - - + if (accelerometer.activate()==0) { led1 = 1; @@ -81,11 +66,11 @@ pc.printf("\nActivated chip\n"); wait(0.5); - //int x=0;//int y=0;int z=0; - for(int i=0; i<5;i++) + + for(int i=0; i<10;i++) { - + /* if (accelerometer.read_x_raw(x_buffer)==0) { //pc.printf("\nThe x-axis LSB is: 0x%x", x); @@ -99,8 +84,10 @@ pc.printf("\nError - could not get xaxis LSB! ....\n"); } + */ + /* if (accelerometer.read_y_raw(y_buffer)==0) { //pc.printf("\nThe x-axis LSB is: 0x%x", x); @@ -114,6 +101,8 @@ pc.printf("\nError - could not get yaxis LSB! ....\n"); } + */ + if (accelerometer.read_z_raw(z_buffer)==0) @@ -121,7 +110,7 @@ //pc.printf("\nThe x-axis LSB is: 0x%x", x); pc.printf("The value of my z_buffer[0] in digit form is: %d in hex: 0x%x \n",z_buffer[0],z_buffer[0]); pc.printf("The value of my z_buffer[1] in digit form is: %d in hex: 0x%x \n",z_buffer[1],z_buffer[1]); - print2bytebinchar(y_buffer); + print2bytebinchar(z_buffer); } else @@ -131,10 +120,7 @@ - //y = accelerometer.read_y(); - - //pc.printf("\nAxis acceleration in x is: %i , y is: %i, z is %z \n", x,y,z); - wait(1); + wait(0.5); } } else @@ -164,7 +150,7 @@ } - wait(3); + wait(2); pc.printf("In loop %d, of repeated initialisation.\n",i); i++; @@ -181,7 +167,7 @@ { pc.printf("Device failed to set into standby...\n"); } - int deviceSystemMode = 0; + pc.printf("\nGet system mode, it should now be standby! ...\n"); if (accelerometer.get_SystemMode(deviceSystemMode)==0) { @@ -193,62 +179,4 @@ } - - - - - - - - - - - - - - /* - while(1) - { - //send procedure - wait(0.07); - switch(number){ - case 0: - if(i2c.write(mcu_address,add,1) == 0){ - number++; - pc.printf("In case 0 loop. The number is: %d \n", number); - led1 = 1; - }else{ - number=0; - pc.printf("In case 0 loop. The number is reset to: %d \n", number); - led1 = 0; - led2 = 0; - led3 = 1; - } - break; - case 1: - if(i2c.read(mcu_address,cmd,6) == 0){ - number++; - pc.printf("In case 1 loop. The number is: %d \n", number); - led2 = 1; - }else{ - number=0; - pc.printf("In case 1 loop. The number is reset to: %d \n", number); - led1 = 0; - led2 = 0; - led3 = 0; - } - break; - case 2: - //get analog data - pc.printf("\r X = %d,Y = %d,Z = %d \n",cmd[1],cmd[3],cmd[5]); - led3 = 1; - wait(0.5); - led1 = 0; - led2 = 0; - led3 = 0; - number=0; - break; - } - }*/ - -} + }