2009-10-08 05:30 AM
Can I read status of a GPIO input pin using bit banding?
2011-05-17 04:25 AM
Can I use bit banding to read the status of a GPIO input pin?
If so, how?2011-05-17 04:25 AM
#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