cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with simple I2C read on STM32F105

andy2399
Senior

I am simply trying to read a few bytes from an I2C memory device using the following code:

    uint8_t buff[ 4 ];
    HAL_I2C_Mem_Read( &hi2c1, ( uint16_t )( 80 << 1 ), 0, I2C_MEMADD_SIZE_16BIT, buff, 4, 10 );

However, when I look at the output on the logic analyser, 1)The slave address does not appear on the bus and 2)I get continuous clocks that never stop).

0693W000005ANzHQAW.pngCan anyone help ?

Andy

2 REPLIES 2
TDK
Guru

Ensure pins are correctly initialized. Probably want a bigger timeout than 10ms.

If you feel a post has answered your question, please click "Accept as Solution".
andy2399
Senior

Thanks for your comments however, the pins are initialised using STM32CubeMX generated code:

    /**I2C1 GPIO Configuration
    PB8     ------> I2C1_SCL
    PB9     ------> I2C1_SDA
    */
    GPIO_InitStruct.Pin = EEPROM_SCL_Pin|EEPROM_SDA_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
    __HAL_AFIO_REMAP_I2C1_ENABLE();
 
    /* I2C1 clock enable */
    __HAL_RCC_I2C1_CLK_ENABLE();

Also, increasing the timeout makes no difference.

Andy