mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
102 lines
3.8 KiB
C
102 lines
3.8 KiB
C
/*********************************************************************************************************************
|
||
* COPYRIGHT NOTICE
|
||
* Copyright (c) 2020,<2C><><EFBFBD>ɿƼ<C9BF>
|
||
* All rights reserved.
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>QQȺ<51><C8BA><EFBFBD><EFBFBD>Ⱥ<EFBFBD><C8BA>824575535
|
||
*
|
||
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC><EFBFBD><EFBFBD>У<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5>;<EFBFBD><CDBE>
|
||
* <20><>ӭ<EFBFBD><D3AD>λʹ<CEBB>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>뱣<EFBFBD><EBB1A3><EFBFBD><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC>İ<EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
*
|
||
* @file L3G4200D
|
||
* @company <09>ɶ<EFBFBD><C9B6><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC><EFBFBD><EFBFBD><EFBFBD>˾
|
||
* @author <09><><EFBFBD>ɿƼ<C9BF>(QQ3184284598)
|
||
* @version <09>鿴doc<6F><63>version<6F>ļ<EFBFBD> <20>汾˵<E6B1BE><CBB5>
|
||
* @Software ADS v1.2.2
|
||
* @Target core TC264D
|
||
* @Taobao https://seekfree.taobao.com/
|
||
* @date 2020-3-23
|
||
* @note
|
||
<09><><EFBFBD>߶<EFBFBD><DFB6>壺
|
||
------------------------------------
|
||
SCL <20>鿴SEEKFREE_SIMIIC<49>ļ<EFBFBD><C4BC>ڵ<EFBFBD>SEEKFREE_SCL<43>궨<EFBFBD><EAB6A8>
|
||
SDA <20>鿴SEEKFREE_SIMIIC<49>ļ<EFBFBD><C4BC>ڵ<EFBFBD>SEEKFREE_SDA<44>궨<EFBFBD><EAB6A8>
|
||
------------------------------------
|
||
********************************************************************************************************************/
|
||
|
||
|
||
|
||
#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]);
|
||
}
|
||
}
|
||
|