Stm32 I2c transmit restart issue
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-03-18 3:45 AM
Posted on March 18, 2015 at 11:45
The S stands for start and the Sr for restart.
How do I generate the repeated start condition without stopping and also send ack and check for ack?
I have been using theHAL_I2C_Master_Transmit andHAL_I2C_Master_Receive functions.
My initialization is given below:
Hi everyone,
I am working with a sensor which communicates using i2c. I am very new to stm 32 and could only figure out the basics of the code.I have successfully obtained data from other sensors using i2c. This particular sensor has the following protocol to obtain data.__GPIOB_CLK_ENABLE();
GPIO_i2c.Mode = GPIO_MODE_AF_OD;
GPIO_i2c.Pull = GPIO_PULLUP;
GPIO_i2c.Pin |= GPIO_PIN_6|GPIO_PIN_7;
//GPIO_Uart.Speed = GPIO_SPEED_LOW;
GPIO_i2c.Alternate = GPIO_AF4_I2C1;
HAL_GPIO_Init(GPIOB, &GPIO_i2c);
__I2C1_CLK_ENABLE();
I2cHandle.Instance = I2C1;
I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
I2cHandle.Init.ClockSpeed = 400000;
I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
I2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_2;
I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
I2cHandle.Init.OwnAddress1 = 0x30F;
and the functions as I am using are given below
HAL_I2C_Master_Transmit(&I2cHandle, (uint16_t)0xB4, (uint8_t*)read1, 1, 10000);
HAL_I2C_Master_Receive(&I2cHandle, (uint16_t)0xB5, (uint8_t *)Buffer1, 3, 10000);
HAL_I2C_Master_Transmit(&I2cHandle, (uint16_t)0x00, (uint8_t*)read2, 3, 10000);
HAL_I2C_Master_Receive(&I2cHandle, (uint16_t)0x01, (uint8_t *)Buffer2, 2, 10000);
where read1 has the address of the register and 0xB4 is address for read ,while 0xB5 is for write.
#restart #i2c #ack
Labels:
- Labels:
-
I2C
This discussion is locked. Please start a new topic to ask your question.
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-03-20 11:58 PM
Posted on March 21, 2015 at 07:58
Try using the so called Memory read varaint (HAL_I2C_Mem_Read)
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-10-14 11:52 PM
yes,use function HAL_I2C_Mem_Read
