This is an example program for the Freescale multi-sensor shield, part number FRDM-FXS-MULTI

Dependencies:   FXAS21000 FXLS8471Q FXOS8700Q MAG3110 MMA8652 MPL3115A2 mbed

main.cpp

Committer:
JimCarver
Date:
2014-06-02
Revision:
1:d3ecb4ecdfda
Parent:
0:e5337522df6f

File content as of revision 1:d3ecb4ecdfda:

/* Copyright (c) 2010-2011 mbed.org, MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "mbed.h"
#include "MAG3110.h"
#include "MPL3115A2.h" // May only be used on a Freescale platform, comment out for others
#include "FXOS8700Q.h"
#include "MMA8652.h"
#include "FXLS8471Q.h"
#include "FXAS21000.h"

#define MPL3115A2_I2C_ADDRESS (0x60<<1)


DigitalOut  red(LED1);

FXLS8471Q acc1(D11, D12, D13, D10);
MMA8652   acc2(A4, A5);
FXOS8700Q_acc combo_acc(A4, A5, FXOS8700CQ_SLAVE_ADDR0);
FXOS8700Q_mag combo_mag(A4, A5, FXOS8700CQ_SLAVE_ADDR0);
MAG3110   mag2(A4, A5);
FXAS21000 gyro(A4, A5);
MPL3115A2 alt(A4, A5, MPL3115A2_I2C_ADDRESS);  // May only be used on a Freescale platform, comment out for others

Serial pc(USBTX, USBRX);



float print_AltimiterValue( unsigned char *dt)
{
    unsigned short altm;
    float faltm;

    /*
    * dt[0] = Bits 12-19 of 20-bit real-time Altitude sample. (b7-b0)
    * dt[1] = Bits 4-11 of 20-bit real-time Altitude sample. (b7-b0)
    * dt[2] = Bits 0-3 of 20-bit real-time Altitude sample (b7-b4)
    */
    altm = (dt[0]<<8) | dt[1];
    //
    if ( dt[0] > 0x7F) {
        altm = ~altm + 1;
        faltm = (float)altm * -1.0f;
    } else {
        faltm = (float)altm * 1.0f;
    }
    //
    faltm = faltm+((float)(dt[2]>>4) * 0.0625f);
    return faltm;
}

float print_TemperatureValue( unsigned char *dt)
{
    unsigned short temp;
    float ftemp;

    /*
    * dt[0] = Bits 4-11 of 16-bit real-time temperature sample. (b7-b0)
    * dt[1] = Bits 0-3 of 16-bit real-time temperature sample. (b7-b4)
    */
    temp = dt[0];
    //
    if ( dt[0] > 0x7F) {
        temp = ~temp + 1;
        ftemp = (float)temp * -1.0f;
    } else {
        ftemp = (float)temp * 1.0f;
    }
    //
    ftemp = ftemp+((float)(dt[1]>>4) * 0.0625f);
    return ftemp;

}


int main()
{
    float acc_data[3], mag_data[3], gyro_data[3];
    MotionSensorDataUnits adata;
    MotionSensorDataUnits mdata;
    int16_t acc_raw[3];
    unsigned char raw_data[8];

    printf("\r\nStarting\r\n\r\n");

    red = 1;
    combo_acc.enable();
    combo_mag.enable();
    mag2.enable();
    alt.Altimeter_Mode();
    printf("FXLS8471 Acc   = %X\r\n", acc1.getWhoAmI());
    printf("MMA8652 Acc    = %X\r\n", acc2.getWhoAmI());
    printf("FXOS8700 Combo = %X\r\n", combo_acc.whoAmI());
    printf("MAG3110 Mag    = %X\r\n", mag2.whoAmI());
    printf("FXAS21000 Gyro = %X\r\n", gyro.getWhoAmI());
    printf("MPL3115A2 Alt  = %X\r\n", alt.getDeviceID());  // May only be used on a Freescale platform, comment out for others
    wait(3);
    
    while(1) {
        acc1.ReadXYZ(acc_data);
        acc1.ReadXYZraw(acc_raw);
        printf("FXLS8471 Acc: X:%1.3f Y:%1.3f Z:%1.3f (Raw X:%3d Y:%3d Z:%3d)\r\n", acc_data[0], acc_data[1], acc_data[2], acc_raw[0], acc_raw[1], acc_raw[2]);

        acc2.ReadXYZ(acc_data);
        acc2.ReadXYZraw(acc_raw);
        printf("MMA8652 Acc:  X:%1.3f Y:%1.3f Z:%1.3f (Raw X:%3d Y:%3d Z:%3d)\r\n", acc_data[0], acc_data[1], acc_data[2], acc_raw[0], acc_raw[1], acc_raw[2]);

        combo_acc.getAxis(adata);
        combo_mag.getAxis(mdata);
        printf("FXOS8700 Acc: X:%1.3f Y:%1.3f Z:%1.3f (Mag X:%4.1f Y:%4.1f Z:%4.1f)\r\n", adata.x, adata.y, adata.z, mdata.x, mdata.y, mdata.z);
        
        gyro.ReadXYZ(gyro_data);
        printf("FXAS21000 Gyro: X:%4.2f Y:%4.2f Z:%4.1f\r\n", gyro_data[0], gyro_data[1], gyro_data[2]);
        
        mag2.getAxis(mdata);
        printf("MAG3110 Mag:    X:%4.1f Y:%4.1f Z:%4.1f\r\n", mdata.x, mdata.y, mdata.z);

        alt.getAllDataRaw(&raw_data[0]);  // May only be used on a Freescale platform, comment out for others
        printf("MPL3115A2 Alt:  %5.1f\r\n", print_AltimiterValue(&raw_data[0]));  // May only be used on a Freescale platform, comment out for others
        printf("MPL3115A2 Temp: %3.1f\r\n", print_TemperatureValue(&raw_data[3]));  // May only be used on a Freescale platform, comment out for others

        printf("\r\n");
        
        red = 1;
        wait(0.5);
        red = 0;
        wait(0.5);
    }
}