102 lines
3.8 KiB
C
Raw Normal View History

2022-01-18 00:58:54 +08:00
/*********************************************************************************************************************
* COPYRIGHT NOTICE
* Copyright (c) 2020,<EFBFBD><EFBFBD><EFBFBD>ɿƼ<EFBFBD>
* All rights reserved.
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>QQȺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱥ<EFBFBD><EFBFBD>824575535
*
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>Ȩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿƼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>;<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD>ӭ<EFBFBD><EFBFBD>λʹ<EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿƼ<EFBFBD><EFBFBD>İ<EFBFBD>Ȩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @file L3G4200D
* @company <EFBFBD>ɶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿƼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>޹<EFBFBD>˾
* @author <EFBFBD><EFBFBD><EFBFBD>ɿƼ<EFBFBD>(QQ3184284598)
* @version <EFBFBD>doc<EFBFBD><EFBFBD>version<EFBFBD>ļ<EFBFBD> <EFBFBD>˵<EFBFBD><EFBFBD>
* @Software ADS v1.2.2
* @Target core TC264D
* @Taobao https://seekfree.taobao.com/
* @date 2020-3-23
* @note
<EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD><EFBFBD>
------------------------------------
SCL <EFBFBD>SEEKFREE_SIMIIC<EFBFBD>ļ<EFBFBD><EFBFBD>ڵ<EFBFBD>SEEKFREE_SCL<EFBFBD><EFBFBD><EFBFBD>
SDA <EFBFBD>SEEKFREE_SIMIIC<EFBFBD>ļ<EFBFBD><EFBFBD>ڵ<EFBFBD>SEEKFREE_SDA<EFBFBD><EFBFBD><EFBFBD>
------------------------------------
********************************************************************************************************************/
#include "zf_stm_systick.h"
#include "SEEKFREE_IIC.h"
#include "SEEKFREE_L3G4200D.h"
int16 gyro_x = 0, gyro_y = 0, gyro_z = 0;
uint8 temperature = 0;
//-------------------------------------------------------------------------------------------------------------------
// @brief L3G4200D<30>Լ캯<D4BC><ECBAAF>
// @param NULL
// @return void
// @since v1.0
// Sample usage: <09><><EFBFBD>øú<C3B8><C3BA><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD>ģ<EFBFBD><C4A3>IIC<49>ij<EFBFBD>ʼ<EFBFBD><CABC>
//-------------------------------------------------------------------------------------------------------------------
void l3g4200d_self_check(void)
{
simiic_write_reg(L3G4200_DEV_ADD, CTRL_REG1_4200, 0x4f);
while(0x4f != simiic_read_reg(L3G4200_DEV_ADD, CTRL_REG1_4200,SIMIIC))
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>
//1 ģ<><EFBFBD>ˣ<EFBFBD><CBA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8>ʼ<EFBFBD><CABC><EFBFBD>
//2 <20><><EFBFBD>ߴ<EFBFBD><DFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>нӺ<D0BD>
//3 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3.3V
//4 <20><><EFBFBD><EFBFBD>û<EFBFBD>е<EFBFBD><D0B5><EFBFBD>ģ<EFBFBD><C4A3>IIC<49>ij<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
//-------------------------------------------------------------------------------------------------------------------
// @brief <20><>ʼ<EFBFBD><CABC>L3G4200D<30><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// @param NULL
// @return void
// @since v1.0
// Sample usage: <09><><EFBFBD>øú<C3B8><C3BA><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD>ģ<EFBFBD><C4A3>SIMIIC<49>ij<EFBFBD>ʼ<EFBFBD><CABC>
//-------------------------------------------------------------------------------------------------------------------
void l3g4200d_init(void)
{
simiic_init();
systick_delay_ms(STM0, 50);
l3g4200d_self_check();
simiic_write_reg(L3G4200_DEV_ADD, CTRL_REG1_4200, 0x4f); //
simiic_write_reg(L3G4200_DEV_ADD, CTRL_REG2_4200, 0x00); //00
simiic_write_reg(L3G4200_DEV_ADD, CTRL_REG3_4200, 0x08); //
simiic_write_reg(L3G4200_DEV_ADD, CTRL_REG4_4200, 0xB0); //+-2000dps
simiic_write_reg(L3G4200_DEV_ADD, CTRL_REG5_4200, 0x00);
temperature = simiic_read_reg(L3G4200_DEV_ADD, OUT_TEMP_4200, SIMIIC);
}
//-------------------------------------------------------------------------------------------------------------------
// @brief <20><>ȡL3G4200D<30><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// @param NULL
// @return void
// @since v1.0
// Sample usage: ִ<>иú<D0B8><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD>Ӳ鿴<D3B2><E9BFB4>Ӧ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//-------------------------------------------------------------------------------------------------------------------
void get_l3g4200d(void)
{
uint8 dat[6];
uint8 status;
status = simiic_read_reg(L3G4200_DEV_ADD, STATUS_REG_4200, SIMIIC);
if( status&0x80 )//<2F><EFBFBD><E9BFB4><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD>ˡ<EFBFBD><CBA1><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB>׼<EFBFBD><D7BC><EFBFBD>ã<EFBFBD><C3A3><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ܶ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݡ<EFBFBD><DDA1><EFBFBD>ȡƵ<C8A1><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǹ<EFBFBD><C7B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>
{
simiic_read_regs(L3G4200_DEV_ADD, OUT_X_L_4200|0X80, dat, 6, SIMIIC); //<2F><><EFBFBD><EFBFBD>0x80<38><30><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>Ҫ<EFBFBD><D2AA><EFBFBD>ֽڶ<D6BD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
gyro_x = (int16)((uint16)dat[1]<<8 | dat[0]);
gyro_y = (int16)((uint16)dat[3]<<8 | dat[2]);
gyro_z = (int16)((uint16)dat[5]<<8 | dat[4]);
}
}