AnsweredAssumed Answered

I2C address scan not working for some I2C slave devices

Question asked by Pranay Dhuri on Jun 13, 2018
Latest reply on Jun 14, 2018 by Pranay Dhuri

Hi,

I am running code to scan available devices on I2C bus by using HAL_I2C_Master_Transmit() .

scan is responding for RTC+EEPROM module and listing I2C addresses perfeclty.

Now I have I2C based optical switches on bus,but it is not being listed in scan, receiving HAL_TIMEOUT /HAL_BUSY flags. 

same Optical switch is working well with Arduino.

following is my I2C initialization:

 

static void MX_I2C3_Init(void)
{

hi2c3.Instance = I2C3;
hi2c3.Init.ClockSpeed = 100000;
hi2c3.Init.DutyCycle = I2C_DUTYCYCLE_2;
hi2c3.Init.OwnAddress1 = 0;
hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c3.Init.OwnAddress2 = 0;
hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c3) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}

}

 

 

 

// MSP init:

 

 

void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
{

GPIO_InitTypeDef GPIO_InitStruct;
if(hi2c->Instance==I2C3)
{
/* USER CODE BEGIN I2C3_MspInit 0 */
__HAL_RCC_I2C3_CLK_ENABLE();
/* USER CODE END I2C3_MspInit 0 */

/**I2C3 GPIO Configuration
PC9 ------> I2C3_SDA
PA8 ------> I2C3_SCL
*/
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_I2C3;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

GPIO_InitStruct.Pin = GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF4_I2C3;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/* Peripheral clock enable */

/* USER CODE BEGIN I2C3_MspInit 1 */

/* USER CODE END I2C3_MspInit 1 */
}

}

 

 

 I am using STM32F207ZG nulcleo board for development and STM32Cube_FW_F2_V1.6.0 SDK.

 

Seeking help in resolving this issue...

Thanks.

Outcomes