Skip to main content
MMARI.1
Senior II
December 22, 2022
Question

trying to read 8 bit port reading and writing . it's working but it's correct?? uint8_t pins = GPIOA->IDR; if(pins == 0xFF){ GPIOC->ODR=0xF000; } else { GPIOC->ODR=0x0000; }

  • December 22, 2022
  • 3 replies
  • 836 views

..

    This topic has been closed for replies.

    3 replies

    waclawek.jan
    Super User
    December 22, 2022

    "Correct" depends on context.

    Generally, it's better to change output pins using the GPIOx_BSRR register, as it changes only those pins which you intend to change, leaving others untouched. But if you always change all output pins of one GPIO at once, using ODR is OK.

    JW

    S.Ma
    Principal
    December 22, 2022

    Use BSRR to get the right way before implementing niche situations that won't likely copy paste next time. While not perfect, check HAL_GPIO functions to get familiar with interacting with HW registers. Then think multitask, interrupt, shared HW registers, volatility....

    MMARI.1
    MMARI.1Author
    Senior II
    December 23, 2022

    hi, i have checked BSRR .

    16bit & 32bit

    GPIOB->ODR = 0xFFFF; and GPIOB->BSRR = 0x0000FFFF; what is exact difference . which is faster .

    which one deliver as parallels port output data .

    correct me if i understood wrong .