AnsweredAssumed Answered

i can't get work accelerometer

Question asked by Dudenkov.Vladimi.001 on Mar 17, 2017
Latest reply on Sep 21, 2017 by Francesco Murru

Lis2dh connect with stm32l151 on i2c bus.

function initial i2c:

I2C_DeInit( I2C1 );

RCC_APB1PeriphClockCmd( RCC_APB1Periph_I2C1, ENABLE );

GPIO_PinAFConfig( GPIOB, GPIO_PinSource9, GPIO_AF_I2C1 );
GPIO_PinAFConfig( GPIOB, GPIO_PinSource8, GPIO_AF_I2C1 );

GPIO_InitTypeDef accelerometer_gpio;
accelerometer_gpio.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
accelerometer_gpio.GPIO_Mode = GPIO_Mode_AF;
accelerometer_gpio.GPIO_Speed = GPIO_Speed_40MHz;
accelerometer_gpio.GPIO_OType = GPIO_OType_OD;
accelerometer_gpio.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init( GPIOB, &accelerometer_gpio );


I2C_InitTypeDef accelerometer_i2c;
accelerometer_i2c.I2C_Ack = I2C_Ack_Enable;
accelerometer_i2c.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
accelerometer_i2c.I2C_ClockSpeed = 100000;
accelerometer_i2c.I2C_DutyCycle = I2C_DutyCycle_2;
accelerometer_i2c.I2C_Mode = I2C_Mode_I2C;
accelerometer_i2c.I2C_OwnAddress1 = 0x15;
I2C_Init( I2C1, &accelerometer_i2c );

I2C_Cmd( I2C1, ENABLE );




And then i trying send SAD+W command on accelerometer (in description he have 0x30-0x33 adresses):

while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
I2C_GenerateSTART(I2C1, ENABLE);
while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
I2C_Send7bitAddress(I2C1, 0x25 << 1, I2C_Direction_Transmitter);
while (! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); << this line!!!
I2C_SendData(I2C1, 0x20);


but on 5 line program is hanging.

may be i do smth wrong?