cancel
Showing results for 
Search instead for 
Did you mean: 

Master board i2c don t comm with slave board, between 2 stm board

SDall
Associate II

Hi, I'm giving the example of the two stm32 boards at this link

https://github.com/sogongbang/STM32CubeF4/tree/master/Projects/STM32F4-Discovery/Examples/I2C/I2C_TwoBoards_ComPolling

I made and copied the connection and the code then I checked several times, everything matches, the problem is that when I execute the hall master i2c trasmitt function, it gives me an error, the master does not connect with the slave:

while(HAL_I2C_Master_Transmit(&I2cHandle, (uint16_t)I2C_ADDRESS, (uint8_t*)aTxBuffer, TXBUFFERSIZE, 10000)!= HAL_OK)
{
/* Error_Handler() function is called when Timeout error occurs.
When Acknowledge failure occurs (Slave don't acknowledge it's address)
Master restarts communication */
if (HAL_I2C_GetError(&I2cHandle) != HAL_I2C_ERROR_AF)
{
Error_Handler();
}
}

The code stop in function Error_Handler()

Tanks

14 REPLIES 14
jiangfan
ST Employee

Please be sure to use same Hardware configuration as mentioned with 2 STM32F4-Discovery boards:

Hardware and Software environment
- STM32F4-Discovery RevB & RevC Set-up
- Connect Master board PB6 to Slave Board PB6
- Connect Master board PB9 to Slave Board PB9
- Connect Master board GND to Slave Board GND

 

SDall
Associate II

Originally a reply in this old thread from 2017: https://community.st.com/t5/stm32-mcus-products/i2c-always-falls-into-hal-i2c-error-af/td-p/399752/page/2

 

Hi Tiago i m using i2c protocol between 2 f 401 re,One master and another slave ,i have the same problem the slave not riconozied address from master ,i have horror on the slave ,horror handle ,i ceked connection,shift register, all,Always same error

Hello @SDall 

Please refer to the I2C examples Projects/STM32F401-Discovery/Examples/I2C available on STM32F4Cube firmware.

 

 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar

There seems no reason to assume that this is the same issue as in that old thread:


@SDall wrote:

using i2c protocol between 2 f401re, One master and another slave


That's a completely different situation!

 

Have you separately tested that 

  1. Your Master implementation works alone, with a standard, known-good slave?
  2. Your Slave implementation works alone, with a standard, known-good master?

Without having first done those basic steps, you have no idea whether the problem(s) is/are in your Slave implementation or your Master implementation - or both!

See:

https://community.st.com/t5/stm32-mcus-boards-and-hardware/i2c/m-p/668411/highlight/true#M18743

 


@SDall wrote:

the slave not riconozied address from master


Are you sure that the Master is actually sending the correct address?

Is your Slave responding with an ACK?

Have you used an oscilloscope to check what's happening on the wires?

 


@SDall wrote:

i have horror on the slave, horror handle 


What do you mean by "horror" here?

 


@SDall wrote:

i ceked connection,


Show what connection you have.

Pullups?

yes already done and tried again about ten times, always the same error

So you're going to have to do some debugging to find out what, exactly, is going wrong.

Start by using an oscilloscope to check what's happening on the wires ...

 

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/tac-p/706966/highlight/true#M49

 

Show your initialization code for the slave. How are you receiving data? Interrupt or polling?

Show your Master code and how you're transmitting.. 
Show your connection diagram between the two boards.

 

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

https://controllerstech.com/stm32-as-i2c-slave-part-1/

My code Is equal of this tutorial,master f 401,slave 401 

The same configuration,exacrly connection inclusive gnd gnd,

No error in interrupt,the slave board Is in crash in debugging...


@SDall wrote:

the slave board Is in crash in debugging...


What, exactly, do you mean by "crash" ?

Use the debugger to find how it gets into this "crashed" condition.

Again, use an oscilloscope to check what's happening on the wires

 


@SDall wrote:

https://controllerstech.com/stm32-as-i2c-slave-part-1/

My code Is equal of this tutorial, master f401, slave 401 


Well, that code is for F103 - not F401.

So why not, as @Saket_Om suggested, just use the example that is specifically for the F4 ?

 

Also, that Controllerstech code is not checking return values from the HAL functions.