You use volatile
to mark variables that are going to change at any moment, in a ISR (Interrupt Service Routine) typically.
You mark them so the compiler doesn't optimize, and always go and pick its actual value. If you don't do that, then an ISR may update a variable while the main "thread" of execution keeps using its old value. That's is a nasty situation to debug.
You only need to mark variables that are used both in the ISR and in the main sketch. If twi_masterBuffer
is not changed inside an ISR, you don't need to mark it with volatile
.
static
is used inside function to mark variables that need to be permanent, i.e., keep their values between calls, but not accessible from outside that function.
volatile
does?