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

Hello i want to write a byte to P0.24 ~~P0.31 without affecting other pins on Port P0 What i shuld i do ? Guide me thank you

Hello i want to write a byte to P0.24 ~~P0.31 without affecting other pins on  Port P0   What i shuld  i  do ? Guide me  thank you

Parents
  • Hi 

    In that case you should use a bitmask to mask out the bits that you want to change. 

    Something like this:

    #define MY_PINS_POS  24
    #define MY_PINS_MASK 0xFF000000
    #define OTHER_PINS_MASK (~MY_PINS_MASK)
    
    // Change P0.24-P0.31 only
    uint8_t my_data = 12;
    NRF_P0->OUT = (NRF_P0->OUT & OTHER_PINS_MASK) | ((uint32_t)my_data << MY_PINS_POS);

    Best regards
    Torbjørn

Reply
  • Hi 

    In that case you should use a bitmask to mask out the bits that you want to change. 

    Something like this:

    #define MY_PINS_POS  24
    #define MY_PINS_MASK 0xFF000000
    #define OTHER_PINS_MASK (~MY_PINS_MASK)
    
    // Change P0.24-P0.31 only
    uint8_t my_data = 12;
    NRF_P0->OUT = (NRF_P0->OUT & OTHER_PINS_MASK) | ((uint32_t)my_data << MY_PINS_POS);

    Best regards
    Torbjørn

Children
Related