cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 and LSM303 no reading data

Bogdan
Senior
Posted on August 10, 2014 at 14:48

Hi all,

i recently started working on a orientation project using iNemo aplication, despite the dificulty of using pre build sensor libs, i said ''i`ll build my own''. Said and done, but when i try to read a single register there is 0x00 data on the buss The I2C works fine, except after sending the read comand ( 0x33) the data is 0x00 0x00 I tryied this reading only one axis, for example the X axis. Bellow is my init routine and the reading function

void LSM303_init(){
i2c_send_cmd(awAddr, CTRL_REG2_A, 0x00);
i2c_send_cmd(awAddr, CTRL_REG1_A, 0x77); // normal mode,data rate to 400hz
i2c_send_cmd(awAddr, CTRL_REG3_A, 0x00); // disable interrupts for DRDY and Click
i2c_send_cmd(awAddr, CTRL_REG4_A, 0x00); // full scale 2G, little endian
i2c_send_cmd(awAddr, CTRL_REG5_A, 0x00); //fifo disable,boot normal
i2c_send_cmd(awAddr, CTRL_REG6_A, 0x00);//disable more interrupts
i2c_send_cmd(awAddr, FIFO_CTRL_REG_A, 0x00); // bypass fifo
i2c_send_cmd(awAddr, INT1_CFG_A, 0x00); // more interrupts disabled
i2c_send_cmd(awAddr, INT2_THS_A, 0x00); // more interrupts disabled
i2c_send_cmd(awAddr, CRA_REG_M, 0x94); // set magnetometer data rate to 30hz, temp sensor enable
i2c_send_cmd(awAddr, CRB_REG_M, 0x40); // set magnetometer gain to 1.9Gauss
i2c_send_cmd(awAddr, MR_REG_M, 0x00); // set mag continouse conversion mode
}

The read function

void LSM303_Read(uint16_t x_a){
//uint16_t x_a;
i2c_start_com();
i2c_wrAddr(awAddr); //0x32
i2c_Wrbyte(OUT_X_H_A); // 0x29 Select Acc Y register
i2c_start_com(); // restart signal
i2c_rdAddr(arAddr);//0x33
uint8_t x_h_a=i2c_rdAck();// get acc x MSB;
uint8_t x_l_a=i2c_rdNack(); // get acc x LSB;
x_a=(x_h_a<<
8
)+x_l_a;
I2Cx->CR1 |= I2C_CR1_STOP; /* Generate a STOP condition */ 
}

Bellow are some screent shots taken with logic analizer on the bus. I am missing something in the config registers? 0690X00000604trQAA.png
1 REPLY 1
Bogdan
Senior
Posted on August 11, 2014 at 07:06

after spending some good hours trying to figure out whats wrong, i got to the conclusion that if i enable the accelerometer alone everything is fine, i get readings on all 3 axis, but if i enable the magnetometer then everything gets stuck.

Anyone experienced this issue before?