cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32 I2c transmit restart issue

varunnalam
Associate
Posted on March 18, 2015 at 11:45

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. 0690X00000605fxQAA.png 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:

__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
2 REPLIES 2
stst9193
Associate II
Posted on March 21, 2015 at 07:58

Try using the so called Memory read varaint (HAL_I2C_Mem_Read)

tianzhongyushui
Associate

yes,use function HAL_I2C_Mem_Read