Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
SCIboard_L3G4200DTR.cpp
00001 /* SCIboard(TM) L3G4200DTR.cpp 00002 Copyright (c) 2013 K. Andres 00003 00004 Permission is hereby granted, free of charge, to any person obtaining a copy 00005 of this software and associated documentation files (the "Software"), to deal 00006 in the Software without restriction, including without limitation the rights 00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00008 copies of the Software, and to permit persons to whom the Software is 00009 furnished to do so, subject to the following conditions: 00010 00011 The above copyright notice and this permission notice shall be included in 00012 all copies or substantial portions of the Software. 00013 00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00020 THE SOFTWARE. 00021 */ 00022 00023 #include "SCIboard_L3G4200DTR.h" 00024 00025 SCIboard_L3G4200DTR::SCIboard_L3G4200DTR(SCIboard_I2C *ptr_I2C, int iDR, int iBW, int iFS) { 00026 float FS[] = {250, 500, 2000}; 00027 unsigned char data[2]; 00028 00029 pI2C = ptr_I2C; 00030 00031 data[0] = GYRREG_CTRL_REG1; 00032 data[1] = 0x0F; // 0xXF = Normal mode with Zen, Yen, Xen 00033 data[1] |= iDR << 6; 00034 data[1] |= iBW << 4; 00035 pI2C->writeRegs(L3G4200DTR_I2C_ADDR, data, 2); 00036 00037 data[0] = GYRREG_CTRL_REG3; 00038 data[1] = 0x08; // Data Ready on DRDY/INT2 00039 pI2C->writeRegs(L3G4200DTR_I2C_ADDR, data, 2); 00040 00041 gyrSF = 32768.0 / FS[iFS]; 00042 00043 data[0] = GYRREG_CTRL_REG4; 00044 data[1] = iFS << 4; 00045 data[1] |= 0x80; // Block Data Update 00046 pI2C->writeRegs(L3G4200DTR_I2C_ADDR, data, 2); 00047 } 00048 00049 unsigned char SCIboard_L3G4200DTR::getDeviceID(void) { 00050 unsigned char data; 00051 pI2C->readRegs(L3G4200DTR_I2C_ADDR, GYRREG_WHO_AM_I, &data, 1); 00052 return data; 00053 } 00054 00055 unsigned char SCIboard_L3G4200DTR::getStatus(void) { 00056 unsigned char data; 00057 pI2C->readRegs(L3G4200DTR_I2C_ADDR, GYRREG_STATUS, &data, 1); 00058 return data; 00059 } 00060 00061 void SCIboard_L3G4200DTR::getData(float *rtn) { 00062 char data[6]; 00063 00064 pI2C->readRegs(L3G4200DTR_I2C_ADDR, GYRREG_OUT_X_L, (unsigned char*)data, 6); 00065 00066 rtn[0] = float(short(data[1] << 8 | data[0])) / gyrSF; 00067 rtn[1] = float(short(data[3] << 8 | data[2])) / gyrSF; 00068 rtn[2] = float(short(data[5] << 8 | data[4])) / gyrSF; 00069 } 00070 00071 void SCIboard_L3G4200DTR::getTemp(float *rtn) { 00072 unsigned char data; 00073 pI2C->readRegs(L3G4200DTR_I2C_ADDR, GYRREG_OUT_TEMP, &data, 1); 00074 *rtn = (char)data; 00075 } 00076
Generated on Wed Jul 13 2022 05:45:34 by
1.7.2
SCIboard mbed base board