Creating a project about A8491 for TT_Mxx

Committer:
ThunderSoft
Date:
Fri Mar 22 07:16:37 2019 +0000
Revision:
0:6fc4594bc1db
Add code about A8491

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ThunderSoft 0:6fc4594bc1db 1 /*
ThunderSoft 0:6fc4594bc1db 2 * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
ThunderSoft 0:6fc4594bc1db 3 * Copyright 2016-2017 NXP
ThunderSoft 0:6fc4594bc1db 4 *
ThunderSoft 0:6fc4594bc1db 5 * Redistribution and use in source and binary forms, with or without modification,
ThunderSoft 0:6fc4594bc1db 6 * are permitted provided that the following conditions are met:
ThunderSoft 0:6fc4594bc1db 7 *
ThunderSoft 0:6fc4594bc1db 8 * o Redistributions of source code must retain the above copyright notice, this list
ThunderSoft 0:6fc4594bc1db 9 * of conditions and the following disclaimer.
ThunderSoft 0:6fc4594bc1db 10 *
ThunderSoft 0:6fc4594bc1db 11 * o Redistributions in binary form must reproduce the above copyright notice, this
ThunderSoft 0:6fc4594bc1db 12 * list of conditions and the following disclaimer in the documentation and/or
ThunderSoft 0:6fc4594bc1db 13 * other materials provided with the distribution.
ThunderSoft 0:6fc4594bc1db 14 *
ThunderSoft 0:6fc4594bc1db 15 * o Neither the name of the copyright holder nor the names of its
ThunderSoft 0:6fc4594bc1db 16 * contributors may be used to endorse or promote products derived from this
ThunderSoft 0:6fc4594bc1db 17 * software without specific prior written permission.
ThunderSoft 0:6fc4594bc1db 18 *
ThunderSoft 0:6fc4594bc1db 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ThunderSoft 0:6fc4594bc1db 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
ThunderSoft 0:6fc4594bc1db 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ThunderSoft 0:6fc4594bc1db 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ThunderSoft 0:6fc4594bc1db 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
ThunderSoft 0:6fc4594bc1db 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
ThunderSoft 0:6fc4594bc1db 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ThunderSoft 0:6fc4594bc1db 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
ThunderSoft 0:6fc4594bc1db 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
ThunderSoft 0:6fc4594bc1db 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ThunderSoft 0:6fc4594bc1db 29 */
ThunderSoft 0:6fc4594bc1db 30
ThunderSoft 0:6fc4594bc1db 31 #include "MMA8491.h"
ThunderSoft 0:6fc4594bc1db 32 #include "mbed.h"
ThunderSoft 0:6fc4594bc1db 33
ThunderSoft 0:6fc4594bc1db 34
ThunderSoft 0:6fc4594bc1db 35
ThunderSoft 0:6fc4594bc1db 36
ThunderSoft 0:6fc4594bc1db 37 MMA8491::MMA8491(PinName sda, PinName scl, PinName en) : MMA8491_i2c(sda,scl),MMA8491_en(en)
ThunderSoft 0:6fc4594bc1db 38 {
ThunderSoft 0:6fc4594bc1db 39 MMA8491_en=1;
ThunderSoft 0:6fc4594bc1db 40 }
ThunderSoft 0:6fc4594bc1db 41
ThunderSoft 0:6fc4594bc1db 42 void MMA8491::acquire_MMA8491_data_g(float * a_data)
ThunderSoft 0:6fc4594bc1db 43 {
ThunderSoft 0:6fc4594bc1db 44
ThunderSoft 0:6fc4594bc1db 45 char data_bytes[7];
ThunderSoft 0:6fc4594bc1db 46 char d[1];
ThunderSoft 0:6fc4594bc1db 47 int status;
ThunderSoft 0:6fc4594bc1db 48 MMA8491_en=1;
ThunderSoft 0:6fc4594bc1db 49 wait(0.001);
ThunderSoft 0:6fc4594bc1db 50 d[0]=MMA8491_STATUS;
ThunderSoft 0:6fc4594bc1db 51 status = MMA8491_i2c.write(MMA8491_I2C_ADDRESS,d,1);
ThunderSoft 0:6fc4594bc1db 52
ThunderSoft 0:6fc4594bc1db 53 MMA8491_i2c.read(MMA8491_I2C_ADDRESS,data_bytes,7);// Read the 6 data bytes - LSB and MSB for X, Y and Z Axes.
ThunderSoft 0:6fc4594bc1db 54 MMA8491_en=0;
ThunderSoft 0:6fc4594bc1db 55
ThunderSoft 0:6fc4594bc1db 56
ThunderSoft 0:6fc4594bc1db 57 // a_data[0]= ((float)((int16_t)data_bytes[1]));
ThunderSoft 0:6fc4594bc1db 58 a_data[0] = ((float)((int16_t)(((data_bytes[1]*256) + (data_bytes[2])))>> 2) * 0.0009765);
ThunderSoft 0:6fc4594bc1db 59 a_data[1] = ((float)((int16_t)(((data_bytes[3]*256) + (data_bytes[4])))>> 2) * 0.0009765);
ThunderSoft 0:6fc4594bc1db 60 a_data[2] = ((float)((int16_t)(((data_bytes[5]*256) + (data_bytes[6])))>> 2) * 0.0009765);
ThunderSoft 0:6fc4594bc1db 61
ThunderSoft 0:6fc4594bc1db 62 }
ThunderSoft 0:6fc4594bc1db 63
ThunderSoft 0:6fc4594bc1db 64