/*******************************************************************************
// 陀螺仪 MPU6050 IIC测试程序
*******************************************************************************/
#include "stm32f10x_lib.h"
#include <math.h> //Keil library
GPIO_InitTypeDef GPIO_InitStructure;
ErrorStatus HSEStartUpStatus;
#define uchar unsigned char
#define uint unsigned int
/*--------定义MMA845x内部地址----------*/
//内部数据定义
unsigned char IIC_ad_main; //器件从地址
unsigned char IIC_ad_sub; //器件子地址
unsigned char *IIC_buf; //发送|接收数据缓冲区
unsigned char IIC_num; //发送|接收数据个数
#define ack 1 //主应答
#define no_ack 0 //从应答
#define MMA845x_IIC_ADDRESS 0x38
/***********************************************************************************************
**
** MMA845xQ Sensor Internal Registers
*/
enum
{
MMA845x_STATUS_00 = 0, // 0x00
MMA845x_OUT_X_MSB, // 0x01
MMA845x_OUT_X_LSB, // 0x02
MMA845x_OUT_Y_MSB, // 0x03
MMA845x_OUT_Y_LSB, // 0x04
MMA845x_OUT_Z_MSB, // 0x05
MMA845x_OUT_Z_LSB, // 0x06
MMA845x_F_STATUS, // 0x08
MMA845x_F_SETUP, // 0x09
MMA845x_TRIG_CFG, // 0x0A
MMA845x_SYSMOD, // 0x0B
MMA845x_INT_SOURCE, // 0x0C
MMA845x_WHO_AM_I, // 0x0D
MMA845x_XYZ_DATA_CFG, // 0x0E
MMA845x_HP_FILTER_CUTOFF, // 0x0F
MMA845x_PL_STATUS, // 0x10
MMA845x_PL_CFG, // 0x11
MMA845x_PL_COUNT, // 0x12
MMA845x_PL_BF_ZCOMP, // 0x13
MMA845x_PL_P_L_THS_REG, // 0x14
MMA845x_FF_MT_CFG, // 0x15
MMA845x_FF_MT_SRC, // 0x16
MMA845x_FF_MT_THS, // 0x17
MMA845x_FF_MT_COUNT, // 0x18
MMA845x_TRANSIENT_CFG, // 0x1D
MMA845x_TRANSIENT_SRC, // 0x1E
MMA845x_TRANSIENT_THS, // 0x1F
公务员年度考核表MMA845x_TRANSIENT_COUNT, // 0x20
MMA845x_PULSE_CFG, // 0x21
MMA845x_PULSE_SRC, // 0x22
MMA845x_PULSE_THSX, // 0x23
MMA845x_PULSE_THSY, // 0x24
MMA845x_PULSE_THSZ, // 0x25
MMA845x_PULSE_TMLT, // 0x26
MMA845x_PULSE_LTCY, // 0x27
MMA845x_PULSE_WIND, // 0x28
MMA845x_ASLP_COUNT, // 0x29
MMA845x_CTRL_REG1, // 0x2A
MMA845x_CTRL_REG2, // 0x2B
MMA845x_CTRL_REG3, // 0x2C
MMA845x_CTRL_REG4, // 0x2D
MMA845x_CTRL_REG5, // 0x2E
MMA845x_OFF_X, // 0x2F
MMA845x_OFF_Y, // 0x30
MMA845x_OFF_Z // 0x31
};
/*
** STATUS Registers
*/
#define STATUS_00_REG 0x00
/*
**
XYZ Data Registers
*/
#define OUT_X_MSB_REG 0x01
#define OUT_X_LSB_REG 0x02
#define OUT_Y_MSB_REG 0x03
#define OUT_Y_LSB_REG 0x04
#define OUT_Z_MSB_REG 0x05
#define OUT_Z_LSB_REG 0x06
/*
** WHO_AM_I Device ID Register
*/
#define WHO_AM_I_REG 0x0D
#define MMA8451Q_ID 0x1A
#define MMA8452Q_ID 0x2A
#define MMA8453Q_ID 0x3A
/*
** F_STATUS FIFO Status Register
*/
#define F_STATUS_REG 0x00
/*
** F_SETUP FIFO Setup Register
*/
#define F_SETUP_REG 0x09
/
*
** TRIG CFG Register
*/
#define TRIG_CFG_REG 0x0A
//
/*
** SYSMOD System Mode Register
*/
#define SYSMOD_REG 0x0B
//
#define FGERR_MASK 0x80
#define FGT_4MASK 0x40
#define FGT_3MASK 0x20
#define FGT_2MASK 0x10
#define FGT_1MASK 0x08
#define FGT_0MASK 0x04
#define FGT_MASK 0x7C
#define SYSMOD1_MASK 0x02
#define SYSMOD0_MASK 0x01
#define SYSMOD_MASK 0x03
/*
** INT_SOURCE System Interrupt Status Register
*/
#define INT_SOURCE_REG 0x0C
//
#define SRC_ASLP_MASK 0x80
#define SRC_FIFO_MASK 0x40
#define SRC_TRANS_MASK 0x20
#define SRC_LNDPRT_MASK 0x10
#define SRC_PULSE_MASK 0x08
#define SRC_FF_MT_1_MASK 0x04
#define SRC_FF_MT_2_MASK 0x02
#define SRC_DRDY_MASK 0x01
/
*
** XYZ_DATA_CFG Sensor Data Configuration Register
*/
#define XYZ_DATA_CFG_REG 0x0E
//
#define HPF_OUT_BIT Bit._4
#define FS1_BIT Bit._1
#define FS0_BIT Bit._0
//
#define HPF_OUT_MASK 0x10
#define FS1_MASK 0x02
#define FS0_MASK 0x01
#define FS_MASK 0x03
#define FULL_SCALE_8G FS1_MASK
#define FULL_SCALE_4G FS0_MASK
#define FULL_SCALE_2G 0x00
/*
** HP_FILTER_CUTOFF High Pass Filter Register
*/
#define HP_FILTER_CUTOFF_REG 0x0F
//
#define PULSE_HPF_BYP Bit._5
#define PULSE_LPF_EN Bit._4
#define SEL1_BIT Bit._1
#define SEL0_BIT Bit._0
//
#define PULSE_HPF_BYP_MASK 0x20
#define PULSE_LPF_EN_MASK 0x10
#define SEL1_MASK 0x02
#define SEL0_MASK 0x01
#define SEL_MASK 0x03
/*
** PL_STATUS Portrait/Landscape Status Register
** PL_PRE_STATUS Portrait/Landscape Previous Data Status Register
*/
#define PL_STATUS_REG 0x10
//
#define NEWLP_MASK 0x80
#define LO_MASK 0x40
#define LAPO1_MASK 0x04
#define LAPO0_MASK 0x02
去时雪满天山路#define LAPO_MASK 0x06
#define BAFRO_MASK 0x01
/*
** PL_CFG Portrait/Landscape Configuration Register
*/
#define PL_CFG_REG 0x11
//
#define DBCNTM_BIT Bit._7
#define PL_EN_BIT Bit._6
//
#define DBCNTM_MASK 0x80
#define PL_EN_MASK 0x40
/*
** PL_COUNT Portrait/Landscape Debounce Register
*/
#define PL_COUNT_REG 0x12
/*
** PL_BF_ZCOMP Back/Front and Z Compensation Register
*/
#define PL_BF_ZCOMP_REG 0x13
//
#define BKFR1_MASK 0x80
#define BKFR0_MASK 0x40
#define ZLOCK2_MASK 0x04
#define ZLOCK1_MASK 0x02
#define ZLOCK0_MASK 0x01
#define BKFR_MASK 0xC0
#define ZLOCK_MASK 0x07
/*
** PL_P_L_THS Portrait to Landscape Threshold Registers
*/
#define PL_P_L_THS_REG 0x14
/*
** FF_MT_CFG Freefall and Motion Configuration Registers
*/
#define FF_MT_CFG_1_REG 0x15
#define FF_MT_CFG_2_REG 0x19
#define ELE_MASK 0x80
#define OAE_MASK 0x40
#define ZEFE_MASK 0x20亲子课
#define YEFE_MASK 0x10
#define XEFE_MASK 0x08
/*
** FF_MT_SRC Freefall and Motion Source Registers
*/
#define FF_MT_SRC_1_REG 0x16
#define FF_MT_SRC_2_REG 0x1A
/
/
#define EA_MASK 0x80
#define ZHE_MASK 0x20
#define ZHP_MASK 0x10
#define YHE_MASK 0x08
#define YHP_MASK 0x04
#define XHE_MASK 0x02
#define XHP_MASK 0x01
/*
** FF_MT_THS Freefall and Motion Threshold Registers
** TRANSIENT_THS Transient Threshold Register
*/
#define FT_MT_THS_1_REG 0x17
#define FT_MT_THS_2_REG 0x1B
#define TRANSIENT_THS_REG 0x1F
//
#define DBCNTM_MASK 0x80
#define THS6_MASK 0x40
#define THS5_MASK 0x20
#define THS4_MASK 0x10
#define THS3_MASK 0x08
#define THS2_MASK 0x04
#define TXS1_MASK 0x02
#define THS0_MASK 0x01
#define THS_MASK 0x7F
/*
** FF_MT_COUNT Freefall Motion Count Registers
*/
#define FF_MT_COUNT_1_REG 0x18
#define FF_MT_COUNT_2_REG 0x1C
/*
** TRANSIENT_CFG Transient Configuration Register
*/
#define TRANSIENT_CFG_REG 0x1D
//
#define TELE_MASK 0x10
#define ZTEFE_MASK 0x08
#define YTEFE_MASK 0x04
#define XTEFE_MASK 0x02
#define HPF_BYP_MASK 0x01
/*
** TRANSIENT_SRC Transient Source Register
*/
#define TRANSIENT_SRC_REG 0x1E
/
/
#define TEA_MASK 0x40
#define ZTRANSE_MASK 0x20
#define ZTRANSEPOL_MASK 0x10
#define YTRANSE_MASK 0x08
#define YTRANSEPOL_MASK 0x04
#define XTRANSE_MASK 0x02
#define XTRANSEPOL_MASK 0x01
/*
** TRANSIENT_COUNT Transient Debounce Register
*/
#define TRANSIENT_COUNT_REG 0x20
/*
** PULSE_CFG Pul Configuration Register
*/
#define PULSE_CFG_REG 0x21
//
#define DPA_MASK 0x80
#define PELE_MASK 0x40
#define ZDPEFE_MASK 0x20
#define ZSPEFE_MASK 0x10
#d
efine YDPEFE_MASK 0x08
#define YSPEFE_MASK 0x04
#define XDPEFE_MASK 0x02
#define XSPEFE_MASK 0x01
/*
** PULSE_SRC Pul Source Register
*/
#define PULSE_SRC_REG 0x22
//
#define PEA_MASK 0x80
#define PAXZ_MASK 0x40
#define PAXY_MASK 0x20
#define PAXX_MASK 0x10
#define PDPE_MASK 0x08
#define POLZ_MASK 0x04
#define POLY_MASK 0x02
#define POLX_MASK 0x01
/*
** PULSE_THS XYZ Pul Threshold Registers
*/
#define PULSE_THSX_REG 0x23
#define PULSE_THSY_REG 0x24
#define PULSE_THSZ_REG 0x25
//
#define PTHS_MASK 0x7F
/*
** PULSE_TMLT Pul Time Window Register
*/
#define PULSE_TMLT_REG 0x26
/*吃柚子有啥好处
** PULSE_LTCY Pul Latency Timer Register
*/
#define PULSE_LTCY_REG 0x27
/
*
** PULSE_WIND Second Pul Time Window Register
*/
#define PULSE_WIND_REG 0x28
/*
** ASLP_COUNT Auto Sleep Inactivity Timer Register
*/
#define ASLP_COUNT_REG 0x29
/*
** CTRL_REG1 System Control 1 Register
*/
#define CTRL_REG1 0x2A
//
#define ASLP_RATE1_MASK 0x80
我的父亲作文600字
#define ASLP_RATE0_MASK 0x40
#define DR2_MASK 0x20
#define DR1_MASK 0x10
#define DR0_MASK 0x08
#define LNOISE_MASK 0x04
#define FREAD_MASK 0x02
#define ACTIVE_MASK 0x01
#define ASLP_RATE_MASK 0xC0
#define DR_MASK 0x38
//
#define ASLP_RATE_20MS 0x00
#define ASLP_RATE_80MS ASLP_RATE0_MASK
#define ASLP_RATE_160MS ASLP_RATE1_MASK
#define ASLP_RATE_640MS ASLP_RATE1_MASK+ASLP_RATE0_MASK
//
#define DATA_RATE_1250US 0x00
#define DATA_RATE_2500US DR0_MASK
#define DATA_RATE_5MS DR1_MASK
#define DATA_RATE_10MS DR1_MASK+DR0_MASK
#define DATA_RATE_20MS DR2_MASK
#define DATA_RATE_80MS DR2_MASK+DR0_MASK
#define DATA_RATE_160MS DR2_MASK+DR1_MASK
#define DATA_RATE_640MS DR2_MASK+DR1_MASK+DR0_MASK
/*
** CTRL_REG2 System Control 2 Register
*/
#define CTRL_REG2 0x2B
//
#define ST_MASK 0x80
#define BOOT_MASK 0x40
#define SMODS1_MASK 0x20
#define SMODS0_MASK 0x10
#define SLPE_MASK 0x04
#define MODS1_MASK 0x02
#define MODS0_MASK 0x01
#define SMODS_MASK 0x18
#define MODS_MASK 0x03
黄河风景名胜区/*
** CTRL_REG3 Interrupt Control Register
*/
#define CTRL_REG3 0x2C
/
/
#define FIFO_GATE_MASK 0x80
#define WAKE_TRANS_MASK 0x40
#define WAKE_LNDPRT_MASK 0x20
#define WAKE_PULSE_MASK 0x10
#define WAKE_FF_MT_1_MASK 0x08
#define WAKE_FF_MT_2_MASK 0x04
#define IPOL_MASK 0x02
#define PP_OD_MASK 0x01
/*
** CTRL_REG4 Interrupt Enable Register
*/
#define CTRL_REG4
0x2D
//
#define INT_EN_ASLP_MASK 0x80
#define INT_EN_FIFO_MASK 0x40
#define INT_EN_TRANS_MASK 0x20
#define INT_EN_LNDPRT_MASK 0x10
#define INT_EN_PULSE_MASK 0x08
#define INT_EN_FF_MT_1_MASK 0x04
#define INT_EN_FF_MT_2_MASK 0x02
#define INT_EN_DRDY_MASK 0x01
/*
** CTRL_REG5 Interrupt Configuration Register
*/
#define CTRL_REG5 0x2E
//
三年级数学手抄报内容#define INT_CFG_ASLP_MASK 0x80
#define INT_CFG_FIFO_MASK 0x40
#define INT_CFG_TRANS_MASK 0x20
#define INT_CFG_LNDPRT_MASK 0x10
#define INT_CFG_PULSE_MASK 0x08
#define INT_CFG_FF_MT_1_MASK 0x04
#define INT_CFG_FF_MT_2_MASK 0x02
#define INT_CFG_DRDY_MASK 0x01
/*
** XYZ Offt Correction Registers
*/
#define OFF_X_REG 0x2F
#define OFF_Y_REG 0x30
#define OFF_Z_REG 0x31
#define MMA845x_Addr 0x1C
unsigned char TX_DATA[4]; //显示据缓存区
unsigned char BUF[10]; //接收数据缓存区
char test=0; //IIC用到
int T_X,T_Y,T_Z; //X,Y,Z轴
//************************************
/*模拟IIC端口输出输入定义*/
#define SCL_H GPIOB->BSRR = GPIO_Pin_6
#define SCL_L GPIOB->BRR = GPIO_Pin_6
#define SDA_H GPIOB->BSRR = GPIO_Pin_7
#define SDA_L GPIOB->BRR = GPIO_Pin_7
#define SCL_read GPIOB->IDR & GPIO_Pin_6
#define SDA_read GPIOB->IDR & GPIO_Pin_7
/
* 函数申明 -----------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void USART1_Configuration(void);
void WWDG_Configuration(void);
void Delay(u32 nTime);
void Delayms(vu32 m);
/* 变量定义 ----------------------------------------------*/
/*******************************/
void DATA_printf(uchar *s,int temp_data)
{
if(temp_data<0){
temp_data=-temp_data;
*s='-';
}
el *s=' ';
*++s =temp_data/1000+0x30;
temp_data=temp_data%1000; //取余运算
*++s =temp_data/100+0x30;
temp_data=temp_data%100; //取余运算
*++s =temp_data/10+0x30;
temp_data=temp_data%10; //取余运算
*++s =temp_data+0x30;
}
/*******************************************************************************
拟人手法的句子
* Function Name : I2C_GPIO_Config
* Description : Configration Simulation IIC GPIO
* Input : None
* Output : None
* Return : None
****************************************************************************** */
void I2C_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_Init(GPIOB, &GPIO_InitStru