資源描述:
《stm8l051f3 串口通訊,模擬i2c讀寫(xiě)mpu6050》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、STM8L051F3串口通訊,模擬I2C讀寫(xiě)MPU6050/*Includes------------------------------------------------------------------*/#include"stm8l15x.h"#include"stm8_eval.h"/**@addtogroupSTM8L15x_StdPeriph_Examples*@{*//***@addtogroupUSART_HyperTerminal_Interrupts*@{*//*Priv
2、atetypedef-----------------------------------------------------------*//*Privatedefine------------------------------------------------------------*///****************************************//定義MPU6050內(nèi)部地址//****************************************#de
3、fineSMPLRT_DIV0x19//陀螺儀采樣率,典型值:0x07(125Hz)#defineCONFIG0x1A//低通濾波頻率,典型值:0x06(5Hz)#defineGYRO_CONFIG0x1B//陀螺儀自檢及測(cè)量范圍,典型值:0x18(不自檢,2000deg/s)#defineACCEL_CONFIG0x1C//加速計(jì)自檢、測(cè)量范圍及高通濾波頻率,典型值: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地址寄存器(默認(rèn)數(shù)值0x68,只讀)#defineSlaveAddress0xD0//IIC寫(xiě)入時(shí)的地址字節(jié)數(shù)據(jù),+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起始信號(hào)//**************************************voidI2C_Start(void){GPIO_Init(GPIOC,GPIO_Pin_1,GPIO_Mode_Out_PP_High_Slow);//setSCLpinasoutputhighGPIO_Init(GP