Skip to content

Setting a single bit in USART control register #486

Answered by Rahix
elenziat asked this question in Q&A
Discussion options

You must be logged in to vote

.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…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@elenziat
Comment options

@Rahix
Comment options

Rahix Jan 4, 2024
Maintainer

Answer selected by elenziat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants