2012-11-06 04:35 AM
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 0x32ReadAddr 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 }2012-11-06 05:13 AM
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)