-
Maybe I have just a wrong understanding of how the API should work. I expected that the follwowing two statements result in the same state of the USCR0B register: ( self.usart.ucsr0b.write(|w| w.udrie0().set_bit()); self.usart
.ucsr0b
.modify(|r, w| unsafe { w.bits(r.bits() | (1 << 5)) }); However, the first variant seems to clear all other bits in the register. Is this expected, or is it a weird problem within my setup? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Now there is one additional detail you should know for AVR in particular. For some registers, a special instruction can be used to just set or clear a single bit. The compiler is smart enough to optimize a |
Beta Was this translation helpful? Give feedback.
.write()
and.modify()
do very different things..write()
writes the whole register where all bits start at their reset value before being modified by the closure. See https://docs.rs/svd2rust/latest/svd2rust/#write..modify()
is a read-modify-write cycle where the current register value is read, then modified by the closure, and then the modified value is written back to the register. Check https://docs.rs/svd2rust/latest/svd2rust/#modify.Now there is one additional detail you should know for AVR in particular. For some registers, a special instruction can be used to just set or clear a single bit. The compiler is smart enough to optimize a
.modify()
call which only sets a single bit to…