LSM303DLHC trouble with magnetometer (MinIMU-9)

Hello,

LSM303DLHC trouble with magnetometer (MinIMU-9). Connected by I2C.

Initialization:

  1. Write address 0x3C register 0x02 value 0.
  2. Verify - read from address 0x3d register 0x02 result - 0.
  3. Read from address 0x3d register 0x00 result - 0x10.
  4. Read from address 0x3d register 0x01 result - 0x20.

Read data:
Read from address 0x3d register 03-08, values always: F0 00 F0 00 F0 00. Why?

Accelerometer working.

Hello.

Could you tell me more about your setup? What are you using to communicate with the MinIMU-9? Also, could you post your code?

- Jeremy

Hello dear people of Pololu,

I’m also using the LSM303DLH, it’s being controlled by a PIC18F46K22 on 3v.

The accelero is working perfectly but it seems like the magneto is not updating it’s axes. I thought the problem was the continues mode or not reading all 6bytes in the same i2c transmission. But I does not seem to work whatever i do.

Help!

void magneto_init()
{
	// setup magnetometer	
	i2c_start();
	/*
	i2c_writeSlaveAddress(SLAVE_ADDRESS_M, I2C_WRITE);
	i2c_writeData(CRA_REG_M);
	i2c_writeData(0b00010100); // set data output rate to 30Hz
	
	i2c_restart();*/
	i2c_writeSlaveAddress(SLAVE_ADDRESS_M, I2C_WRITE);	
	i2c_writeData(MR_REG_M);
	i2c_writeData(0b00000000); // go from sleep mode to continuous mode
	/*
	i2c_restart();
	i2c_writeSlaveAddress(SLAVE_ADDRESS_M, I2C_WRITE);	
	i2c_writeData(CRB_REG_M);
	i2c_writeData(0b00000000);
	
	i2c_restart();
	i2c_writeSlaveAddress(SLAVE_ADDRESS_M, I2C_WRITE);	
	i2c_writeData(SR_REG_M);
	i2c_writeData(0b00000100); // the 1 means internal voltage regulator enabled
	*/
	i2c_stop();
}


void magneto_updateXYZ()
{
	unsigned char X_H_M, X_L_M;
	unsigned char Y_H_M, Y_L_M;
	unsigned char Z_H_M, Z_L_M;

	i2c_start();		
	i2c_writeSlaveAddress(SLAVE_ADDRESS_M, I2C_WRITE);	
	i2c_writeData(OUT_X_H_M||0b10000000);	// OUT_X_H_M with MSb 1 for stream
	i2c_restart();		
	i2c_writeSlaveAddress(SLAVE_ADDRESS_M, I2C_READ);
	
	X_H_M = i2c_readData();
	i2c_ack();
	X_L_M = i2c_readData();
	i2c_ack();
	Y_H_M = i2c_readData();
	i2c_ack();
	Y_L_M = i2c_readData();
	i2c_ack();
	Z_H_M = i2c_readData();	
	i2c_ack();
	Z_L_M = i2c_readData();
	
	i2c_nack();
	i2c_stop();
	
	magX = (X_H_M << 8 | X_L_M);
	magY = (Y_H_M << 8 | Y_L_M);
	magZ = (Z_H_M << 8 | Z_L_M);
}

Here’s the code i hope you can help me out here!

thanks in advance,

greeting!

Nevermind lovely people of Pololu,

it works !!

Hello,
Thanks for your help.
I using OR-AVR-M128-S controller and OR-USB-UART for my robots (in Russian). Programming language - jscript + hta.
I solved the problem. The problem in low voltage ~ 1,6v. Voltage 4,5v solve the problem.
Thank you.

TeHuster i think problem in line:
i2c_writeData(OUT_X_H_M||0b10000000); // OUT_X_H_M with MSb 1 for stream
try:
i2c_writeData(0x03); // the register is autoincremented after each read

Page 26 documentation (Magnetic signal interface reading/writing):
To minimize the communication between the master and magnetic digital interface of the
LSM303DLH, the address pointer is updated automatically without master intervention.