Your chip has 16 I/O pins that are divided in two groups of 8 pins each, called
bank A and
bank B. Physical pins
1-8 of the chip are used for
bank A pins and physical pins
21-28 are used for
bank B pins. Rest of the physical pins (
9-20) are used for other purposes like setting the device address, connecting power and ground, etc.
The device has quite a few registers that can be individually written/read in order to perform different operations. Two of those registers are
GPIOA (0x12) and
GPIOB (0x13) 8-bit registers that can be used to read/write whole
bank A or
bank B at a time. This means that if you read
GPIOA register, you will get 8 bits of data and each of them will give you the value of different pin in
bank A. The same goes for writing - if you want to write some value to any pin in
bank A, you have to write whole
GPIOA register setting values of all pins in bank A at once.
How to calculate bank value
As already mentioned, each bank consists of 8 bit which corresponds to 8 pins values. Here's how the value is computed for
P8 P7 P6 P5 P4 P3 P2 P1
and here is for
P28 P27 P26 P25 P24 P23 P22 P21
where each of
PXX corresponds to physical pin number XX.
So if you want to turn
P25 on and
P28 off, you would write value of
00010001 (in binary) which is 0x11 in hexadecimal to the
Each of your
A2 pins should either be connected to ground or to
VCC, depending on the address you want to get. You should never left it without any connection since this will make it
float. This means for the chip it may have different state each time it is read.
So if you want to have address
0x20, you should connect all of them to ground. If you want to have
0x27, you should connect all of them to
Please note that this is simplified explanation of how this chip works. It has different mode of operations and some more features that can be configured using chip's registers. You can read about such details in the datasheet.