标题:
STM32 MPU6050获取加速度角速度代码
[打印本页]
作者:
wind@
时间:
2018-12-27 14:06
标题:
STM32 MPU6050获取加速度角速度代码
MPU6050三轴陀螺仪通过IIC读取获取角速度及加速度代码
单片机源程序如下:
//连接方式 :请参考interface.h文件
//部份源码来源网络--请试用24小时后删除
#include "stm32f10x.h"
#include "interface.h"
#include "LCD1602.h"
#include "IRCtrol.h"
#include "motor.h"
#include "UltrasonicCtrol.h"
#include "redvoid.h"
#include "Usart_Interrupt.h"
#include "stm32f10x_i2c.h"
#include "MPU_IIC.h"
#include "uart.h"
#include "usart.h"
u8 pBuffer;
u8* ppBuffer;
s16 AccelGyro[7]={0};
unsigned char cmd_flag = 0;
unsigned char testbuf[5]="abcdf";
//全局变量定义
unsigned int speed_count=0;//占空比计数器 50次一周期
char front_left_speed_duty=SPEED_DUTY;
char front_right_speed_duty=SPEED_DUTY;
char behind_left_speed_duty=SPEED_DUTY;
char behind_right_speed_duty=SPEED_DUTY;
unsigned char tick_5ms = 0;//5ms计数器,作为主函数的基本周期
unsigned char tick_1ms = 0;//1ms计数器,作为电机的基本计数器
unsigned char tick_200ms = 0;//刷新显示
char ctrl_comm = COMM_STOP;//控制指令
char ctrl_comm_last = COMM_STOP;//上一次的指令
unsigned char continue_time=0;
int main(void)
{
delay_init();
USART1Conf(115200);
// printf("MPU6050 test1--->\n");
I2C_MPU6050_Init();
// printf("MPU6050 test2--->\n");
MPU6050_IniTIalize();
// printf("MPU6050 test3--->\n");
while(1)
{
//MPU6050_I2C_ByteWrite(SlaveAdress,pBuffer,0x68);
//MPU6050_I2C_ByteWrite(u8 slaveAddr, u8 pBuffer, u8 writeAddr)
//MPU6050_I2C_BufferRead(SlaveAdress,ppBuffer,0x68,8);//NumByteToRead?
//MPU6050_I2C_BufferRead(u8 slaveAddr, u8* pBuffer, u8 readAddr, u16 NumByteToRead)
MPU6050_GetRawAccelGyro(AccelGyro);
printf("MPU6050 test3--->\r\n");
// printf("ACC_X = %10.5d\r\n",AccelGyro[0]);
// printf("ACC_Y = %10.5d\r\n",AccelGyro[1]);
// printf("ACC_Z = %10.5d\r\n",AccelGyro[2]);
// printf("GYRO_X = %10.5d\r\n",AccelGyro[3]);
// printf("GYRO_Y = %10.5d\r\n",AccelGyro[4]);
// printf("GYRO_Z = %10.5d\r\n",AccelGyro[5]);
printf("ACC_X = %d\r\n",AccelGyro[0]);
printf("ACC_Y = %d\r\n",AccelGyro[1]);
printf("ACC_Z = %d\r\n",AccelGyro[2]);
printf("GYRO_X = %d\r\n",AccelGyro[3]);
printf("GYRO_Y = %d\r\n",AccelGyro[4]);
printf("GYRO_Z = %d\r\n",AccelGyro[5]);
Delay_us(500000);
}
}
复制代码
所有资料51hei提供下载:
MPU6050.7z
(190.45 KB, 下载次数: 84)
2018-12-28 02:03 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
chaqs3
时间:
2019-8-23 15:52
AccelGyro前三个代表的是xyz轴上的加速度吗?
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1