cancel
Showing results for 
Search instead for 
Did you mean: 

LIS3DH g-sensor read byte problem

rasimoguzturk
Associate III
Posted on November 06, 2012 at 13:35

hi all, i am working on LIS3DH acc. with stm32f100c8.i read WHO AM I byte(0x33) but i cannot read z axis value(2Dh)..please any suggestions? here is my read one byte funct.

slaveAddress 0x32

ReadAddr 0x2D //z axis 

void ReadOneByte(){

GPIO_SetBits(GPIOA,GPIO_Pin_8); //led on

Delay(1);

while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));

I2C_GenerateSTART(I2C1, ENABLE);

while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));

I2C_Send7bitAddress(I2C1, slaveAddress, I2C_Direction_Transmitter);

while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));

I2C_SendData(I2C1, ReadAddr); 

while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BTF) == RESET);

I2C_GenerateSTART(I2C1, ENABLE);

while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));

I2C_Send7bitAddress(I2C1, slaveAddress, I2C_Direction_Receiver); 

while(I2C_GetFlagStatus(I2C1, I2C_FLAG_ADDR) == RESET);

I2C_AcknowledgeConfig(I2C1, DISABLE);  

(void)I2C1->SR2;

I2C_GenerateSTOP(I2C1, ENABLE);

while(I2C_GetFlagStatus(I2C1, I2C_FLAG_RXNE) == RESET);

data = I2C_ReceiveData(I2C1);

while(I2C1->CR1 & I2C_CR1_STOP);

GPIO_ResetBits(GPIOA,GPIO_Pin_8);  // led off

}
1 REPLY 1
stm32forum
Associate II
Posted on November 06, 2012 at 14:13

You must first enable the accelerometer by setting the crtlreg1 and crtlreg2 registers before you can read data.

Call Write_accel_reg(crtlreg1 , &B00111111)

Call Write_accel_reg(crtlreg4 , &B10000000)