Skip to main content
Explorer
January 27, 2024
Solved

AF bit I2C_SR2 register

  • January 27, 2024
  • 2 replies
  • 2119 views

Hello,

STM8S208RB.

How can you read the AF bit in the I2C_SR2 register?

MykolaLevun_0-1706369511589.png

When I try to read this bit, it is always 0 even if this bit is set to 1 (In debug mode I look at this bit that it is set to 1). For example, the following condition

MykolaLevun_1-1706369895465.png

 

always gives the result: 0b00000000. The result is always 0b00000000 even if the AF bit is set to 1. Why?

 

    This topic has been closed for replies.
    Best answer by MykolaLevun

    Thanks,

    when I read the bit with the debugger it was set to 1 and everything was fine. When I read the bit by the software, it was reset to 0 (The bit simply did not have time to be set. And since commands are executed slowly in debugging mode, the bit had time to set). You just had to add a delay in the code and the program started working correctly.

    2 replies

    Visitor II
    January 27, 2024

    Status bits in SR registers cant' be set to active level by software. You can only clear active level. AF bit is rc_w0. This means you can only write it to 0. And I don't understand why do you need to set this bit to 1?

     

    Graduate II
    January 28, 2024

    Are you sure, that this bit does not change between time you read it by software and by debugger ?

    Visitor II
    January 28, 2024

    I am sure you can't set this bit to 1 by software.

    RM0016 page 312:
    Bit 2 AF: Acknowledge failure.
    – Set by hardware when no acknowledge is returned.
    – Cleared by software writing 0, or by hardware when PE=0.

    RM0016 page 33:
    rc_w0: Software can read and clear this bit by writing 0. Writing ‘1’ has no effect on the bit value.

    You didn't tell me why do you want to force an Acknowledge failure?

     

    Graduate II
    January 28, 2024

    Sorry, that was question to original post. May be he read that bit by software in moment when bit is cleared, but with debugger in moment when bit is set.