2017-03-17 02:14 AM
Lis2dh connect with stm32l151 on i2c bus.
function initial i2c:
I2C_DeInit( I2C1 );
RCC_APB1PeriphClockCmd( RCC_APB1Periph_I2C1, ENABLE ); RCC_AHBPeriphClockCmd( RCC_AHBPeriph_GPIOB, 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);while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));but on 5 line program is hanging.
may be i do smth wrong?
#stm32l151 #lis2dh2017-09-21 02:52 PM
Hi,
See my question, and, maybe, a solution:
https://community.st.com/0D50X00009XkYN7SAN
Regards,
Francesco