SPI Accelerometer Hello World program

Dependencies:   FXLS8471 mbed

Committer:
AswinSivakumar
Date:
Mon Apr 24 18:57:33 2017 +0000
Revision:
4:87df61d02921
Parent:
3:9eae869bdf8e
updated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AswinSivakumar 4:87df61d02921 1 /*
AswinSivakumar 4:87df61d02921 2 * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
AswinSivakumar 4:87df61d02921 3 * Copyright 2016-2017 NXP
AswinSivakumar 4:87df61d02921 4 *
AswinSivakumar 4:87df61d02921 5 * Redistribution and use in source and binary forms, with or without modification,
AswinSivakumar 4:87df61d02921 6 * are permitted provided that the following conditions are met:
AswinSivakumar 4:87df61d02921 7 *
AswinSivakumar 4:87df61d02921 8 * o Redistributions of source code must retain the above copyright notice, this list
AswinSivakumar 4:87df61d02921 9 * of conditions and the following disclaimer.
AswinSivakumar 4:87df61d02921 10 *
AswinSivakumar 4:87df61d02921 11 * o Redistributions in binary form must reproduce the above copyright notice, this
AswinSivakumar 4:87df61d02921 12 * list of conditions and the following disclaimer in the documentation and/or
AswinSivakumar 4:87df61d02921 13 * other materials provided with the distribution.
AswinSivakumar 4:87df61d02921 14 *
AswinSivakumar 4:87df61d02921 15 * o Neither the name of the copyright holder nor the names of its
AswinSivakumar 4:87df61d02921 16 * contributors may be used to endorse or promote products derived from this
AswinSivakumar 4:87df61d02921 17 * software without specific prior written permission.
AswinSivakumar 4:87df61d02921 18 *
AswinSivakumar 4:87df61d02921 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AswinSivakumar 4:87df61d02921 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AswinSivakumar 4:87df61d02921 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AswinSivakumar 4:87df61d02921 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AswinSivakumar 4:87df61d02921 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AswinSivakumar 4:87df61d02921 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AswinSivakumar 4:87df61d02921 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AswinSivakumar 4:87df61d02921 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AswinSivakumar 4:87df61d02921 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AswinSivakumar 4:87df61d02921 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AswinSivakumar 4:87df61d02921 29 */
AswinSivakumar 3:9eae869bdf8e 30 #include "FXLS8471.h"
AswinSivakumar 0:6b858a805a38 31 #include "mbed.h"
AswinSivakumar 0:6b858a805a38 32
AswinSivakumar 0:6b858a805a38 33 // Initialize Serial port
AswinSivakumar 0:6b858a805a38 34 Serial pc(USBTX, USBRX);
AswinSivakumar 0:6b858a805a38 35
AswinSivakumar 0:6b858a805a38 36 // Initialize pins for I2C communication for sensors. Set jumpers J6,J7 in FRDM-STBC-AGM01 board accordingly.
AswinSivakumar 3:9eae869bdf8e 37 FXLS8471 accel(D11, D12, D13, D10);
AswinSivakumar 3:9eae869bdf8e 38
AswinSivakumar 0:6b858a805a38 39
AswinSivakumar 1:d8ca07afb3ec 40
AswinSivakumar 1:d8ca07afb3ec 41
AswinSivakumar 0:6b858a805a38 42 int main()
AswinSivakumar 0:6b858a805a38 43 {
AswinSivakumar 1:d8ca07afb3ec 44
AswinSivakumar 1:d8ca07afb3ec 45 // Configure Accelerometer FXOS8700, Magnetometer FXOS8700 & Gyroscope FXAS21002
AswinSivakumar 3:9eae869bdf8e 46 accel.FXLS8471_config();
AswinSivakumar 3:9eae869bdf8e 47
AswinSivakumar 1:d8ca07afb3ec 48
AswinSivakumar 0:6b858a805a38 49 float accel_data[3]; float accel_rms=0.0;
AswinSivakumar 3:9eae869bdf8e 50
AswinSivakumar 1:d8ca07afb3ec 51 printf("Begin Data Acquisition....\r\n\r\n");
AswinSivakumar 0:6b858a805a38 52 wait(0.5);
AswinSivakumar 0:6b858a805a38 53
AswinSivakumar 0:6b858a805a38 54 while(1)
AswinSivakumar 0:6b858a805a38 55 {
AswinSivakumar 3:9eae869bdf8e 56 accel.acquire_FXLS8471_data_g(accel_data);
AswinSivakumar 0:6b858a805a38 57 accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3);
AswinSivakumar 1:d8ca07afb3ec 58 printf("%4.2f,%4.2f,%4.2f,\t",accel_data[0],accel_data[1],accel_data[2]);
AswinSivakumar 0:6b858a805a38 59 wait(0.005);
AswinSivakumar 3:9eae869bdf8e 60
AswinSivakumar 1:d8ca07afb3ec 61 printf("\n\r");
AswinSivakumar 1:d8ca07afb3ec 62
AswinSivakumar 1:d8ca07afb3ec 63
AswinSivakumar 0:6b858a805a38 64 }
AswinSivakumar 0:6b858a805a38 65
AswinSivakumar 0:6b858a805a38 66 }