2024-01-27 08:43 AM - edited 2024-01-27 08:44 AM
Hello,
STM8S208RB.
How can you read the AF bit in the I2C_SR2 register?
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
always gives the result: 0b00000000. The result is always 0b00000000 even if the AF bit is set to 1. Why?
Solved! Go to Solution.
2024-01-29 05:40 AM
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.
2024-01-27 09:19 AM
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?
2024-01-28 09:47 AM
Are you sure, that this bit does not change between time you read it by software and by debugger ?
2024-01-28 10:31 AM
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?
2024-01-28 10:38 AM
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.
2024-01-28 11:18 AM
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).
2024-01-29 05:40 AM
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.