cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 I2C Addressing Problem

Sany
Associate III

Hello!

I have a new project with a STM32F407VET6 and a STM32F103xxx over a RJ45 Jack with I2C.
i worked a lot of time with I2C EEPROMs and it works fine, but my communication between the 2 STM's are horrible, or i am too confused.

i found the tutorial on https://controllerstech.com/stm32-as-i2c-slave-part-1 

in this tutorial, has the Slave the Address 0x12 (without shifting <<1) 

the code of the master:

 

 

  /* USER CODE BEGIN 2 */

  uint16_t slaveADDR = 0x12<<1;
  uint8_t TxData[6] = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6};
  while (1)
  {
	  HAL_I2C_Master_Transmit(&hi2c1, slaveADDR, TxData, 6, 1000);
	  HAL_Delay (1000);
  }

 

 

okay, here are the address shifted, but my slave are not receiving data on 0x24.

my logic analyzer says, the master sends data to the address 0x24 (it's shifted.. <<1) and not to 0x12. I used the function HAL_I2C_IsDeviceReady(), but i am wondering, in the description of this function are no comments like "shifted address" or any comment..

can anyone help me, what is right for the communication?

Is my slave address 0x12 (without shifting) right? and the master communicates to 0x12<<1 (also 0x24 ?) 

edit 1: in a STM32 Example on the fw lib, are the adresses 0x12F by the way....

 

i am confused..

Thank you! :)

12 REPLIES 12

Hi @TDK ,

I got same trouble above, that is:

HAL_I2C_IsDeviceReady(&hi2c2, 0x12, ...); always be "HAL_BUSY". I tried many ways, but it is not correct now. Really appreciate you if there is an explanation.

Best regards,

Thuan

thuanalg_0-1757564845815.png

 

void I2C_Scan(I2C_HandleTypeDef *hi2c, uint8_t *Addr)
{
	HAL_StatusTypeDef stat ;

    //for(uint8_t addr = 0x01; addr < 0x7F; addr++)
    {
    	stat = HAL_I2C_IsDeviceReady(hi2c, (0x12 << 1), 10, 1000);
        if(stat == HAL_OK)
        {
            printf("Found I2C device at 0x%02X\r\n", 0x12 << 1);
            *Addr = ( 0x12 << 1);
            //break;
        }
    }
}

 

HAL_BUSY indicates SDA or SCL is held low which is a hardware issue.

If you still can't get it, make a new thread and put relevant information in there.

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

Hi @TDK ,

Thank you so much. I tell a bit more about my device:

- STM32F407G-DISC1

thuanalg_0-1757597415144.png

- It could function with SPI1, but couldn't work well with I2C1.

- I tried to measure frequency of SCL/PB6, but the result was incorrect ( it should be 100 KHz, but I didn't see that.)

 You said "which is a hardware issue", I will verify it.

Best regards,

Thuan Nguyen Thai