Skip to content
Discussion options

You must be logged in to vote

Well, the answer is actually not that straight forward :)

I interpret this to mean that it isn't atomic as there is one read operation and one write operation.

Basically, this is correct. The calls to .modify() get lowered into instructions to first read the register, modify the value, and then write it back. Similar to the instructions that the typical |= or &= statements in AVR C code generate.

So the resulting update of the register is not atomic. If you need it to be, you have to wrap the .modify() call in a critical section using avr_device::interrupt::free(). Or in certain cases use .write() instead which is atomic by writing a whole new value in a single instruction (but only for…

Replies: 1 comment 2 replies

Comment options

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

@Rahix
Comment options

Answer selected by K4LCIFER
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