Hi all, i am new in 32 bits microcontrollers,i am configuring the accelerometer LSM303DLHC using the I2C interface in the stm32f411ve discovery board, i write and receive the data from the accelerometer but the data is not steady
in resume i am writing three registers
//*****************************register 0x23**************************************** //the address is 0x32 i2cbuf[0]=0x23;//register 0x23 i2cbuf[1]=0x08;// set +/- 2g range and high resolution enable (datasheet accel) HAL_I2C_Master_Transmit(&hi2c1,address,i2cbuf,2,10);//write 0x08 in the 0x23 register //the write/read operation is correct because after this config i have checked it this way: //reading the written register: i2cbuf[0]=0x23; HAL_I2C_Master_Transmit(&hi2c1,address,i2cbuf,1,10);//go to 0x23 register i2cbuf[1]=0; HAL_I2C_Master_Receive(&hi2c1,address,&i2cbuf[1],1,10);//read the 0x23 register value //and in the debugging mode i get i2cbuf[1]=0x08 so the write is ok //*****************************register 0x20**************************************** //test write register 0x20 i2cbuf[0]=0x20; i2cbuf[1]=0x97;//normal data rate,normal mode power and z,x,y enable (i tried all the data rates but anything works) HAL_I2C_Master_Transmit(&hi2c1,address,i2cbuf,2,10);//write 0x97 in the 0x20 register //*****************************register 0x28**************************************** i2cbuf[0]=0x28;//register where is located the x accelerometer data HAL_I2C_Master_Transmit(&hi2c1,address,i2cbuf,1,10);//go to 0x28 register i2cbuf[1]=0; HAL_I2C_Master_Receive(&hi2c1,address,&i2cbuf[1],6,10);//read 6 bytes from 0x28 register //(x low,x high,y low,y high,z low,z high) //any of this values are steady, all are constantly changing: ax=(i2cbuf[2]<<8|i2cbuf[1]);//build the x value ay=(i2cbuf[4]<<8|i2cbuf[3]);//build the y value az=(i2cbuf[6]<<8|i2cbuf[5]);//build the z value
i think i am missing to config a register but i dont know what , at the beginning i didnt configure the 0x20 register and ax,ay and az lectures were 0 , but i realized that in the 0x20 register the default config was 0x00 (this is power down mode), then in started to set values in this register then ax,ay and az got some strange variables values.
please help and thanks.