Hi Jiang,
you have an error in your function:
void mag_init(){ //initialization that configures MAG3110
I2C_SingleByteWrite(MAG_CTRL_REG1,0x00); //standby mode
I2C_SingleByteWrite(MAG_CTRL_REG2,0x80); //auto reset
I2C_SingleByteWrite(MAG_CTRL_REG1,0x01); //active
}
It has to be as in the demo-board code:
void mag_init(void)
{
hal_dev_mag3110_init(); //Initialize I2C modules
hal_dev_mag3110_write_reg(MAG_CTRL_REG1,0x00); //Standby mode
hal_dev_mag3110_write_reg(MAG_CTRL_REG2,0x80); //Auto reset
hal_dev_mag3110_write_reg(MAG_CTRL_REG1,0x01); //Active
}
You have not properly initialized the MAG3110 device. Please take a look on the original code in the "hal_i2c.c" file.
I think it helps you.
Best Regards,
Stano.