cancel
Showing results for 
Search instead for 
Did you mean: 

Volatile uint8_t variable in interrupts

hospodar
Associate III
Posted on April 14, 2015 at 21:51

Hello,

I have function

fifo_read(RxFifo, &rx, 1)

which reads byte from FIFO buffer. I want to use this function in two different interrupt handlers. I have declared rx variable as follows

volatile
uint8_t rx;

but there is warning like this when I call function: passing 'volatile uint8_t *' to parameter of type 'void *' discard qualifiers. What is wrong? Thank you
2 REPLIES 2
Posted on April 14, 2015 at 22:59

When used in a normal writing sense, volatile means do so immediately, and every time it changes, don't cache it in a register, or fold it over multiple operations. You're passing it as a pointer, so the function isn't going to optimize away the write. With things writing into the variable via a pointer once, they aren't going to care if it's volatile, or not.

What specifically needs the volatile is the code that reads the value, to ensure it re-reads it every time the code asks it to check, rather than read it once into a register.

You need to determine if the fifo function writes it more than once, or checks the value, and then you cast the pointer to avoid the warning. Or you read it into a holding variable, and then write it to rx if the fifo function was successful.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hospodar
Associate III
Posted on April 14, 2015 at 23:51

In ISR, function check if there is some byte in FIFO, because function returns 1 if there are some byte. Processor goes to this ISR when there is some received byte from UART and another function moves it to FIFO.

Timer sends interupt request when there is all bytes from UART stored in FIFO. In timer ISR, the same function is intend to read all these bytes from FIFO in cycle. 

I supposed variable which used in ISR must be volatile.