Skip to main content
Visitor II
April 30, 2024
Question

I2C

  • April 30, 2024
  • 2 replies
  • 1757 views

Hello 

I am new with STM32 boards. I have 2 STM32 boards, and I am trying to get I2C communication between them. The boards I use are: NUCLEO-G071RB as the master, and STM32F412G-DISCO as the slave.

I success to send a response from the slave to the master once, but at other recalls I could not, unless I disconnect the slave's power and restarts it.

How can I solve the issue?

    This topic has been closed for replies.

    2 replies

    Super User
    April 30, 2024

    @MichaelR wrote:

     I am new with STM32 boards.


    Do you have experience with any other microcontroller(s)?

    Do you have experience with I2C in general?

     


    @MichaelR wrote:

    I am trying to get I2C communication between them. ?


    The classic mistake when doing this is to try to do both ends at once.

    The trouble with that approach is that, when you have problems, you can't tell whether the issues are in the Master, or in the Slave - or both.

    So I would strongly suggest that you concentrate on one end at a time:

    https://www.avrfreaks.net/s/topic/a5C3l000000UYYaEAO/t146630?comment=P-1401100

     


    @MichaelR wrote:

    How can I solve the issue?


    Impossible to tell as we can't see what you have done!

    Sounds like your code is getting itself stuck in some bad state...

    Again, per the link above, concentrate on getting one end of the link working at a time - in particular, provide good debug/instrumentation/diagnostics...

     

    #BothEnds

    MichaelRAuthor
    Visitor II
    April 30, 2024

    I further debugged the code, and found out that the problem is that after transmitting the data, the slave handles an error callback with error code 4. Can you help me how do I handle this error that the slave will continue to get communication? 

    Super User
    April 30, 2024

    Start by looking-up what error code 4 means.

    But, again, you're left not knowing if that's due to a problem (or problems) in the Master, or in the Slave - or both.

     


    @MichaelR wrote:

     Can you help me how do I handle this  


    Again, don't try to do it all at once - get one end fully working, debugged, and understood before moving on to the other:

    https://www.avrfreaks.net/s/topic/a5C3l000000UYYaEAO/t146630?comment=P-1401100 

     

    Graduate II
    April 30, 2024

    Do you use pull up resistors ? that might be the reason

     

    1.png

    MichaelRAuthor
    Visitor II
    April 30, 2024

    I don't use no pull up resistor. Should I use?

    MichaelR_0-1714485768976.png

     

    Super User
    April 30, 2024

    @MichaelR wrote:

    I don't use no pull up resistor. Should I use?


    That's really basic to the operation of I2C! Not specific to STM32.

    Sounds like you need to do some reading-up on the fundamentals:

    https://community.st.com/t5/stm32-mcus-products/i2c-interface-with-adxl345-using-stm32f446re/m-p/658323/highlight/true#M240123 

     

    Note that The internal pull-ups are not suitable for use as I2C bus pull-ups - you need to use external pullups.