cancel
Showing results for 
Search instead for 
Did you mean: 

AF bit I2C_SR2 register

MykolaLevun
Associate III

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

6 REPLIES 6
AA1
Senior III

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?

 

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

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?

 

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.

You asked: The result is always 0b00000000 even if the AF bit is set to 1 (by software). Why?

And I explained that AF bit is always read as 0 because you can't set it to 1 by software (and by the debugger).

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.