2012-11-01 11:54 PM
I need some help setting up I2C connection to LIS302DL or a generic I2C accelerometer. I need some code examples to get the accelerometer working. Thanks in advance.
2012-11-02 03:13 AM
Have you looked at the iNemo stuff?
http://www.st.com/internet/evalboard/product/250367.jsp
http://www.st.com/internet/com/SOFTWARE_RESOURCES/SW_COMPONENT/SW_FUNCTION/inemo_gui_2_0_0.zip
2012-11-02 04:00 AM
Sorry but I think iNemo is unrelated. I'll try to explain better.
I have an STM32VLDiscovery board and a LIS302DL accelerometer. They are connected using i2c to the stm32vl discovery.LIS302DL is provided in an adapter board where I connectedLIS side -> STM32VL sideVDD -> 3v3CS -> 3v3SCL -> PB6SDx -> PB7SDO -> 3v3GND -> GNDI have to accomplish a very simple task: get data from i2c and put data to usart.I2C is initialized using the following code:static void I2C1_GPIO_Config(void){ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); GPIO_InitTypeDef GPIO_InitStructure; I2C_InitTypeDef I2C_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Init(GPIOB, &GPIO_InitStructure); I2C_Cmd(I2C1, ENABLE); I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStructure.I2C_ClockSpeed = 100000; I2C_InitStructure.I2C_OwnAddress1 = 0; I2C_Init(I2C1, &I2C_InitStructure);}Read from i2c is done byI2C_GenerateSTART(I2C1, ENABLE);while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));I2C_Send7bitAddress(I2C1, 0x1d, I2C_Direction_Transmitter);while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));I2C_SendData(I2C1, 0x20);while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));I2C_GenerateSTART(I2C1, ENABLE);while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));I2C_Send7bitAddress(I2C1, 0x3B, I2C_Direction_Receiver);while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));data = I2C_ReceiveData(I2C1);while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED));I2C_GenerateSTOP(I2C1, ENABLE);I'm using Atollic free version.Code gets stuck onwhile(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));