Hi im working on stm32f4. I need to read 8 pin and sum the values after convert like binary to decimal. For example if the values of 8 bits are 000000110, my CardID
must be 6. i used this, but there can be better way:
CardID = (GPIOD->IDR & GPIO_Pin_8) +
(GPIOD->IDR & GPIO_Pin_9)*2 +
(GPIOD->IDR & GPIO_Pin_10)*4 +
(GPIOD->IDR & GPIO_Pin_11)*8 +
(GPIOD->IDR & GPIO_Pin_12)*16 +
(GPIOD->IDR & GPIO_Pin_13)*32 +
(GPIOD->IDR & GPIO_Pin_14)*64 +
(GPIOD->IDR & GPIO_Pin_15)*128;
Hint: i know the value of GPIO_Pin_8,GPIO_Pin_9....GPIO_Pin_15.
Can we do the AND operation with a number of combinations?
#define GPIO_Pin_8 ((uint16_t)0x0100) /* Pin 8 selected */
#define GPIO_Pin_9 ((uint16_t)0x0200) /* Pin 9 selected */
#define GPIO_Pin_10 ((uint16_t)0x0400) /* Pin 10 selected */
#define GPIO_Pin_11 ((uint16_t)0x0800) /* Pin 11 selected */
#define GPIO_Pin_12 ((uint16_t)0x1000) /* Pin 12 selected */
#define GPIO_Pin_13 ((uint16_t)0x2000) /* Pin 13 selected */
#define GPIO_Pin_14 ((uint16_t)0x4000) /* Pin 14 selected */
#define GPIO_Pin_15 ((uint16_t)0x8000) /* Pin 15 selected */