AnsweredAssumed Answered

LIS3DH g-sensor read byte problem

Question asked by nazuhin on Nov 6, 2012
Latest reply on Nov 6, 2012 by Edje
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
          
}     

Outcomes