欢迎来到天天文库
浏览记录
ID:14440149
大小:50.00 KB
页数:16页
时间:2018-07-28
《stm8l051f3 串口通讯,模拟i2c读写mpu6050》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、STM8L051F3串口通讯,模拟I2C读写MPU6050/*Includes------------------------------------------------------------------*/#include"stm8l15x.h"#include"stm8_eval.h"/**@addtogroupSTM8L15x_StdPeriph_Examples*@{*//***@addtogroupUSART_HyperTerminal_Interrupts*@{*//*Priv
2、atetypedef-----------------------------------------------------------*//*Privatedefine------------------------------------------------------------*///****************************************//定义MPU6050内部地址//****************************************#de
3、fineSMPLRT_DIV0x19//陀螺仪采样率,典型值:0x07(125Hz)#defineCONFIG0x1A//低通滤波频率,典型值:0x06(5Hz)#defineGYRO_CONFIG0x1B//陀螺仪自检及测量范围,典型值:0x18(不自检,2000deg/s)#defineACCEL_CONFIG0x1C//加速计自检、测量范围及高通滤波频率,典型值:0x01(不自检,2G,5Hz)#defineACCEL_XOUT_H0x3B#defineACCEL_XOUT_L0x3C#d
4、efineACCEL_YOUT_H0x3D#defineACCEL_YOUT_L0x3E#defineACCEL_ZOUT_H0x3F#defineACCEL_ZOUT_L0x40#defineTEMP_OUT_H0x41#defineTEMP_OUT_L0x42#defineGYRO_XOUT_H0x43#defineGYRO_XOUT_L0x44#defineGYRO_YOUT_H0x45#defineGYRO_YOUT_L0x46#defineGYRO_ZOUT_H0x47#defineG
5、YRO_ZOUT_L0x48#definePWR_MGMT_10x6B//电源管理,典型值:0x00(正常启用)#defineWHO_AM_I0x75//IIC地址寄存器(默认数值0x68,只读)#defineSlaveAddress0xD0//IIC写入时的地址字节数据,+1为读取/*Privatemacro-------------------------------------------------------------*//*Privatevariables-------------
6、--------------------------------------------*///externuint8_tdata1;uint8_tCY;uint8_tOutData1=0;uint8_tDataFlag=0;uint8_tOutData[];/*Privatefunctionprototypes-----------------------------------------------*/voidI2C_Start(void);uint8_tI2C_RecvACK();voi
7、dI2C_SendACK(uint8_tack);voidI2C_SendByte(uint8_tdat);uint8_tI2C_RecvByte();voidI2C_Stop();voidSingle_WriteI2C(uint8_tREG_Address,uint8_tREG_data);uint8_tSingle_ReadI2C(uint8_tREG_Address);uint16_tGetData(uint8_tREG_Address);voidInitMPU6050();voidDel
8、ay();voidDelay2(uint16_tnCount);voidUsart_Tx(void);//**************************************//I2C起始信号//**************************************voidI2C_Start(void){GPIO_Init(GPIOC,GPIO_Pin_1,GPIO_Mode_Out_PP_High_Slow);//setSCLpinasoutputhighGPIO_Init(GP
此文档下载收益归作者所有