Skip to main content
johnfitzgerald9
Associate III
October 8, 2009
Question

Can I read status of a GPIO input pin using bit banding?

  • October 8, 2009
  • 2 replies
  • 795 views
Posted on October 08, 2009 at 14:30

Can I read status of a GPIO input pin using bit banding?

    This topic has been closed for replies.

    2 replies

    clive2
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 13:25

    #define PERIPH_BB_BASE ((uint32_t)0x42000000)

    #define PERIPH_BASE ((uint32_t)0x40000000)

    #define APB1PERIPH_BASE PERIPH_BASE

    #define APB2PERIPH_BASE (PERIPH_BASE + 0x10000)

    #define AHBPERIPH_BASE (PERIPH_BASE + 0x20000)

    #define GPIOA_BASE (APB2PERIPH_BASE + 0x0800)

    #define GPIOB_BASE (APB2PERIPH_BASE + 0x0C00)

    #define GPIOC_BASE (APB2PERIPH_BASE + 0x1000)

    #define GPIOD_BASE (APB2PERIPH_BASE + 0x1400)

    #define GPIOE_BASE (APB2PERIPH_BASE + 0x1800)

    #define GPIOF_BASE (APB2PERIPH_BASE + 0x1C00)

    #define GPIOG_BASE (APB2PERIPH_BASE + 0x2000)

    #define GPIO_IDR_OFF (0x08) // Input Data register offset

    // For example GPIO PA.05

    #define GPIO_BASE GPIOA_BASE

    #define GPIO_BIT 5

    u32 *BitBandAddr;

    BitBandAddr = (u32 *)(PERIPH_BB_BASE + (((GPIO_BASE - PERIPH_BASE) + GPIO_IDR_OFF) * 32) + (GPIO_BIT * 4));

    if (*BitBandAddr)

    puts(''Bit High'');

    else

    puts(''Bit Low'');

    The address of PA.05 should be 0x42210114 if my math is correct.

    -Clive

    johnfitzgerald9
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:25

    Can I use bit banding to read the status of a GPIO input pin?

    If so, how?