6461 views|4 replies

28

Posts

1

Resources
The OP
 

MPU6050 temperature reading and conversion and serial communication, please guide [Copy link]

I want to read the temperature of 6050 and display it on the serial assistant of the host PC, but all the data displayed on the serial port is garbled squares, The code is as follows: #include#include typedef unsigned char u8; typedef unsigned int u16; //******************************************** //Define MPU6050 internal address //************************************************ #define SMERT_DIV 0x19 //25. Sampling frequency divider. Sampling frequency = gyroscope output frequency (DLPF_CFG) / (1 + SMPLRT_DIV) #define CONFIG 0X1A //26. Configuration #define GYRO_CONFIG 0x1b //27. Gyroscope configuration #define ACCEL_CONFIG 0x1c //28. Accelerometer configuration #define ACCEL_XOUT_H 0x3b //59. High 8 bits of the X-axis of the accelerometer measurement value #define ACCEL_XOUT_L 0x3C //60. Low 8 bits of the X-axis of the accelerometer measurement value #define ACCEL_YOUT_H 0x3D //61. High 8 bits of the Y-axis of the accelerometer measurement value #define ACCEL_YOUT_L 0x3E //62. Low 8 bits of the Y-axis of the accelerometer measurement value #define ACCEL_ZOUT_H 0x3F //63. High 8 bits of the Z-axis of the accelerometer measurement value #define ACCEL_ZOUT_L 0x40 //64. The lower 8 bits of the Z axis of the accelerometer measurement value #define TEMP_OUT_H 0x41 //65. The upper 8 bits of the temperature measurement value #define TEMP_OUT_L 0x42 //66. The lower 8 bits of the temperature measurement value #define GYRO_XOUT_H 0x43 //67. The upper 8 bits of the X axis of the gyroscope measurement value #define GYRO_XOUT_L 0x44 //68. The lower 8 bits of the X axis of the gyroscope measurement value #define GYRO_YOUT_H 0x45 //69. The upper 8 bits of the Y axis of the gyroscope measurement value #define GYRO_YOUT_L 0x46 //70. Low 8 bits of Y-axis measured value of gyroscope #define GYRO_ZOUT_H 0x47 //71. High 8 bits of Z-axis measured value of gyroscope #define GYRO_ZOUT_L 0x48 //72. Low 8 bits of Z-axis measured value of gyroscope #define PWR_MGMT_1 0x6b //107. Power control 1 #define WHU_AM_I 0x75 //117. 6-bit I2C address register of MPU-60X0 #define SlaveAddress 0xd0 //Address byte data when IIC writes, +1 is read //****************************************************************************************************** //**********************************Delay************************************************************ //******************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************* unsigned int i,j; for(i=0;iThere should be no problem with the conversion. I think the problem is the conversion (I have read a lot of information, but I still don't understand how to convert). Please guide me... It would be nice to recommend some information, thank you
This post is from 51mcu

Latest reply

When you use IIC to read data, you should first find the address of the device, right? Only when you find the device can you operate it. If you don't find the device, whose register can you operate?  Details Published on 2018-7-6 09:08
 

424

Posts

8

Resources
2
 
This is probably because your iic program has a problem. Here is a program for reading mpu6250. Please check it yourself.

MPUxxxx测试过.rar

70.21 KB, downloads: 43

This post is from 51mcu
 
 
 

875

Posts

1

Resources
3
 
When you use IIC to read data, you should first find the address of the device, right? Only when you find the device can you operate it. If you don't find the device, whose register can you operate?
This post is from 51mcu

Comments

Master, the MPU addresses for reading and writing are written in IIC. Can you help me check if there is any problem? Thank you for your hard work. /******************************************************************************** * Function name: I2C_mpu6050Write(unsigned char addr,  Details Published on 2018-7-7 19:57
 
 
 

28

Posts

1

Resources
4
 
Cao Wei 1993 posted on 2018-7-6 09:08 You use IIC to read data, first you should find the address of this device, right? Only when you find this device can you operate this device....
Master, the MPU addresses for reading and writing are all written in IIC. Please help me check if there is any problem. Thank you for your hard work./******************************************************************************* * Function name: I2C_mpu6050Write(unsigned char addr,unsigned char dat) * Function function: Write a data to an address of mpu6050 * Input: None * Output: None ******************************************************************************/ void I2C_mpu6050Write(u8 addr,u8 dat) { I2C_start(); I2C_sendbyte(0xd0); I2C_sendbyte(addr); I2C_sendbyte(dat); I2C_stop(); } /******************************************************************************* * Function name: I2C_mpu6050Read(unsigned char addr) * Function function: Read a data of an address of mpu6050 * Input: None * Output: None **********************************************************************************/ u8 I2C_mpu6050Read(u8 addr) { u8 num; I2C_start(); I2C_sendbyte(0xd0); I2C_sendbyte(addr); I2C_start(); I2C_sendbyte(0xd1); num=I2C_readbyat(); I2C_stop(); return num; }


This post is from 51mcu
 
 
 

28

Posts

1

Resources
5
 
I looked at the program provided by the merchant. I can basically understand it, that is, Integer to string conversionhere. //******************************************** //Integer to string conversion //************************************************ void lcd_printf(uchar *s,int temp_data) { if(temp_data<0) { temp_data=-temp_data; *s='-'; } else *s=' '; *++s =temp_data/100+0x30; temp_data=temp_data%100; //Remainder operation *++s =temp_data/10+0x30; temp_data=temp_data%10; //Remainder operation *++s =temp_data+0x30; } Adding 0x30 at the end, what does it mean? I don't understand???
This post is from 51mcu
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list