#define LED_PIN (1U << 5)
GPIOA->ODR |= LED_PIN; // set bit 5 -- LED on
GPIOA->ODR &= ~LED_PIN; // clear bit 5 -- LED off
Clearing meant ANDing with the complement of the mask. But ADC1->ISR = ADC_ISR_ADRDY; is a plain assignment, and ADC_ISR_ADRDY is a mask with bit 0 set. Read literally, that line writes a 1 into bit 0 and a 0 into every other bit of the status register, the opposite of clearing bit 0, and apparently destroying everything else.
Activity6.2.5.Guess: How Does That Clear Anything?
ADC_ISR_ADRDY has bit 0 set and every other bit clear, and the line assigns it to the whole register. Make a guess: how could that clear the ready bit without disturbing anything else?
The answer is that this registerโs bits do not behave like ordinary memory. ADRDY is a write-1-to-clear bit, rc_w1 in the reference manualโs notation. For such a bit:
Figure6.2.12.The reference manualโs description of ADC_ISR (RM0490 ยง14.12.1). The row under the bit numbers gives each bitโs access type: rc_w1, read, cleared by writing 1, for ADRDY in bit 0 and for the other flags.
So the assignment does exactly what is wanted: bit 0 receives a 1 and is cleared, while every other bit receives a 0 and is left untouched. The register is not being overwritten; it is being sent one instruction per bit.
Now consider what ADC1->ISR &= ~ADC_ISR_ADRDY; would do. The compiler has to read the whole register, clear one bit in the copy, and write all 32 bits back. That write puts a 1 into every status bit that happened to be set when the read occurred, and on this register, writing a 1 means clear. So every other flag that was already raised at the moment of the read would be wiped out, including one you had not looked at yet and were about to handle. You would lose events you never knew had happened.
And it would not even do the job you asked for. The point of the operation was to clear ADRDY, so the read-modify-write puts a 0 into that bit position, and writing a 0 to an rc_w1 bit does nothing at all. ADRDY would still be set. The line manages to destroy the flags you cared about while leaving the one flag you meant to clear exactly as it was.
This is why status registers are built this way. A flag register is written by two parties (the hardware sets bits, your code clears them), and a read-modify-write cannot safely share a register with a writer it cannot see. Write-1-to-clear removes the conflict: your code names the single bit it means to clear and says nothing about the others.
Figure6.2.13.Why the read-modify-write is wrong twice over. Start with three flags set. A plain assignment writes a 1 into ADRDY and a 0 into everything else, so ADRDY clears and the others are untouched. The &= ~ version reads all 32 bits, clears ADRDY in its copy, and writes the lot back, which sends a 1 to every flag that was already set, clearing OVR and EOC, while sending a 0 to ADRDY, which does nothing. The flags you needed are gone and the one you meant to clear is still set.
The reference manual labels every register field with how it may be accessed: rw for ordinary read-write bits, r for read-only, rs for bits you can set but not clear (writing 0 does nothing, and ADEN and ADSTART are both rs), rc_w1 for read, cleared by writing 1, and rc_w0 for the opposite convention, cleared by writing 0. The digit in the name tells you which value does the clearing, so it is worth reading rather than assuming. When you come across a status register you have not used before, check the access type before you decide how to clear a flag.