Skip to main content
Graduate
July 21, 2025
Question

I2C Loopback using bare-metal code

  • July 21, 2025
  • 2 replies
  • 612 views

Hello All, I am trying to do a loopback test between 2 i2c's on the same board, using bare metal coding and interrupts, and the clk is HSI, 16MHz. How the i2c i configured as slave is failing to acknowledge the address sent by master i2c.
Here is a zip file containing the project.

    This topic has been closed for replies.

    2 replies

    Super User
    July 21, 2025

    You already have a thread on this - marked as solved:

    I2C Loopback Test using STM32F429ZI

    maya16Author
    Graduate
    July 21, 2025

    That was using HAL(API), this is register level programming.

    Super User
    July 21, 2025

    So compare what happens in your bare-metal code with what happens in the (working) HAL code.

    Step through both of them - see where they differ.

    The chip neither knows nor cares what your code uses - it just needs to have the correct register setting, etc.

     

    PS:

    You seem to have switched both slave and master to bare-metal.

    It would be more sensible to do just one at a time - otherwise you don't know whether the problem(s) are in the Master, or the Slave - or both!

    https://community.st.com/t5/stm32-mcus-products/two-nucleo-boards-stm32f446re-and-stm32h723zg-communicate/m-p/737695/highlight/true#M264992

     


    @maya16 wrote:

    slave is failing to acknowledge the address sent by master i2c.


    So is the master actually sending the correct address?

    Or is the Slave not correctly recognising its address?

    Or both?!

    maya16Author
    Graduate
    July 25, 2025

    I do not have a logic analyzer or oscilloscope to check by the signals, i can only depend on the debuggers.
    Here is an updated code, i referred the HAL one, and used polling for master and interrupt for slave.
    The address is for being sent on the data line is getting stored on the Data Register of master, but it's getting stuck while checking for ADDR bit. For slave, the slave address is stored correctly in the OAR1 register.