Chosen Solution

Hello, I run the program on 51, the data has no problem. However, when I change the program and run it on atmega128. The HMC5883 compass outputs wrong data, which has no application value. But the acceleration and output data of gyroscope has no problem. The x, y, z can arrive at 5530 the top which seems to be beyond the scope. Another question is: void conversion(unsigned int temp_data) { wan=temp_data/10000+0x30 ; temp_data=temp_data%10000; //complementation qian=temp_data/1000+0x30 ; temp_data=temp_data%1000; //complementation bai=temp_data/100+0x30 ; temp_data=temp_data%100; //complementation shi=temp_data/10+0x30 ; temp_data=temp_data%10; //complementation ge=temp_data+0x30; } Why I should add 0 x30 to get the values? By the way, using a self-test, three of the output shaft is 4095. Regards.

@gavin93 here is the datasheet for the compass. HMC5883L_3-Axis_Digital_Compass_IC(1).pdf Otherwise it is an error within your circuitry and since we do not know the design, It’ll be a tough one to answer.