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;i" h="I2C_mpu6050Read(addr);" h,l;[="" i2c_mpu6050write(accel_config,0x00);="" i2c_mpu6050write(config,0x06);="" i2c_mpu6050write(gyro_config,0x18);="" i2c_mpu6050write(pwr_mgmt_1,0x00);="" i2c_mpu6050write(smert_div,0x07);="" init_uart();[="" init_uart()[="" initmpu6050();[="" initmpu6050()[="" l="I2C_mpu6050Read(addr+1);" main()[="" pcon="0x80;" ps="1;" return="" ronghe(u8="" s[="" sbuf="det1;" scon="0x50;" send_data)[="" seripushsend(temp_out_h);[="" seripushsend(u8="" short="" size]="" tem="(short)" tem;[="" th1="0xf3;" tl1="0xf3;" tmod="0x20;" tr0="1;" tr1="1;" u8="" while(!ti);ti="0;" while(1)[="" {="" {[="" }="" }[="" 串口中断设为高优先级别[="" 低通滤波频率,典型值:0x06(5hz)[="" 启动定时器="" 实现波特率4800(系统时钟12mhz)="" 打开定时器0中断="" 电源管理,典型值:0x00(正常启用)[="" 设置加速度计的满量程范围为:±2g[="" 设置陀螺仪的满量程范围为:±2000°="" 陀螺仪采样率,典型值:0x07(125hz)[="">There 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
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
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?
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
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; }
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???