2021-07-15 11:01 PM
Having difficulty to communicate with SPS30 on I2C. As a beginner I am having difficulty to understand how to debug the problem as it just returns 255 in in_buff. This topic may sound to broad, however, If someone can guide me the direction to make sure that my I2C communication is well established.
static void MX_I2C1_Init(void)
{
hi2c1.Instance = I2C1;
hi2c1.Init.Timing = 100000; //@16MHz
hi2c1.Init.OwnAddress1 = 0;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c1.Init.OwnAddress2 = 0;
hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
//other codes
}
while()
{
HAL_UART_Transmit(&huart2, "ok2", 4, 100);
HAL_I2C_Master_Transmit(&hi2c1, (devAddr << 1), 0x1103, 2, 100);
HAL_I2C_Master_Transmit(&hi2c1, (devAddr << 1), 0x1103, 2, 100);
HAL_Delay(100);
HAL_I2C_Mem_Read(&hi2c1, (devAddr<<1), 0xD304, MemAddSize, in_buff, Size, 100);
HAL_UART_Transmit(&huart2,in_buff, 3, 100);
HAL_Delay(1000);
}
2021-07-16 02:25 AM
I2C is one of the more complex interfaces - so maybe not the best starting place for a beginner?
Do you have (access to) an oscilloscope or logic analyser to see what is actually happening on the wires?
Two of the commonest problems with I2C are: