This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF24LE1, example PRX in nRFgo SDK, why not volatile global array?

Hello everybody, I study transceiver nrf24LE1. I'm trying to understand example of PRX in nRFgo SDK (Enhanced_shockburst_examples):

/

    / Global variables
    uint8_t payload [3];
     
    // Radio interrupt
    NRF_ISR () // #define NRF_ISR () void nrf_isr (void) interrupt 8 // RF interrupt (0x4b)
    {
    ...
         // Read payload
    ...
           hal_nrf_read_rx_payload (payload);
    ...
    }

Please explain why uint8_t payload [3] is not declared as volatile ? Thank you so much!!!

Parents
  • Hi Artem,

    Could you explain a little bit more why you think volatile is needed ? My understanding is that we are not using the payload anywhere outside of the interrupt handler. hal_nrf_read_rx_payload () simply read the RX buffer and put into the payload array. We have no dependency on the payload value in main loop for example.

  • Since it's used in the interrupt handler the optimiser won't throw it out however it's defined, as long as the interrupt routine is compiled in. Volatile, as a keyword, isn't particularly well-defined and does different things between compilers. Technically if you want to be sure that every read access goes back to the array to re-read the data incase it's changed you could declare it volatile, in practice, it makes very little difference.

Reply
  • Since it's used in the interrupt handler the optimiser won't throw it out however it's defined, as long as the interrupt routine is compiled in. Volatile, as a keyword, isn't particularly well-defined and does different things between compilers. Technically if you want to be sure that every read access goes back to the array to re-read the data incase it's changed you could declare it volatile, in practice, it makes very little difference.

Children
No Data
Related