QMC5883L.c
uint8_t init_QMC5883L(){
	// init the I2C1 peripheral and the SDA/SCL GPIO pins
	init_i2c1();
	uint8_t buf[2];
	// init QMC5883L
	buf[0] = SET_RESET_PERIOD_REGISTER;
	buf[1] = 0x01;
	uint8_t i2c_err = i2c_write(QMC5883L_ADRESS, buf, 2);
	if(i2c_err) return i2c_err;
	buf[0] = CONTROL_REGISTER_1;
	// continuous mode, 200Hz data rate, 8G scale, 512 oversampling ratio
	buf[1] = 0b00011101;
	i2c_err = i2c_write(QMC5883L_ADRESS, buf, 2);
	if(i2c_err) return i2c_err;
	return 0;
}
// initialize the I2C1 peripheral and configure the magnetometer
initialize the I2C1 peripheral and configure the magnetometer
initialize the I2C1 peripheral and configure the magnetometer
uint8_t init_QMC5883L(){
	init_i2c1();
	uint8_t buf[2];
	buf[0] = SET_RESET_PERIOD_REGISTER;
	buf[1] = 0x01;
	uint8_t i2c_err = i2c_write(QMC5883L_ADRESS, buf, 2);
	if(i2c_err) return i2c_err;
	buf[0] = CONTROL_REGISTER_1;
	buf[1] = 0b00011101;
	i2c_err = i2c_write(QMC5883L_ADRESS, buf, 2);
	if(i2c_err) return i2c_err;
	return 0;
}
uint8_t init_QMC5883L ( ) { init_i2c1 ( ) ; uint8_t buf [ 2 ] ; buf [ 0 ] = SET_RESET_PERIOD_REGISTER ; buf [ 1 ] = 0x01 ; uint8_t i2c_err = i2c_write ( QMC5883L_ADRESS , buf , 2 ) ; if ( i2c_err ) return i2c_err ; buf [ 0 ] = CONTROL_REGISTER_1 ; buf [ 1 ] = 0b00011101 ; i2c_err = i2c_write ( QMC5883L_ADRESS , buf , 2 ) ; if ( i2c_err ) return i2c_err ; return 0 ; }
initialize the I2C1 peripheral and configure the magnetometer
initialize the I2C1 peripheral and configure the magnetometer
// init the I2C1 peripheral and the SDA/SCL GPIO pins // init QMC5883L // continuous mode, 200Hz data rate, 8G scale, 512 oversampling ratio