The GPIB has eight data lines, which are used to send information one byte (8 bits) at a time. Command messages use seven of the eight bits, as shown in Figure 1, below:
Figure 1. GPIB Addressing Protocol
Bits 0 through 4 indicate the primary address of the device, for which the Talker/Listener assignment is intended. If bit 5 is high, the device should listen. If bit 6 is high, the device should talk. Bit 7 is a "don't care" bit. Its value is ignored, so it is interpreted as a value of zero in command messages.
Each device on the bus must have a unique address. This address consists of a primary address (PAD) and a secondary address (SAD). As you can see from Figure 1, five of the data lines are used to indicate the GPIB primary address. This means that you could have a value from 0 to 31, for a total of 32 (2 to the power of 5) addresses; however,
PAD 31 is never used as a primary address
, because it is used for special command messages. This leaves a total of 31 possible primary addresses. The Controller-In-Charge (CIC) for a bus is almost always at PAD 0, so the instruments on a bus can have primary addresses from 1 to 30. A common mistake in working with the GPIB is assigning the same address to the controller board and the instrument, which will result in an EADR error (addressing error).
The GPIB secondary address is identical in its range of 0 to 30, which allows for a total of 961 (31 x 31) possible GPIB addresses, but the secondary address is very rarely used (the SAD is typically set to zero). Talker/Listener assignments are part of the primary addressing information, so with PADs you use either bit 6 or bit 5 when you send a command message. This might prompt you to ask, "How do I send the SAD information?" For secondary addresses, you set both bits 6 and 5 high when you send a command message. If you need to communicate with a device that has a secondary address, you need to indicate its primary address first and then immediately indicate its secondary address.
The easiest way to play around with primary and secondary addressing, command messages, and data messages is to use the Interactive Control (IBIC). For example, if you have a board at PAD 0 and an instrument with PAD 2 and SAD 4, and you want the board to talk and the instrument to listen, you would send the following command message in IBIC:
The \x40 stands for hex 40, which represents the binary pattern of 0 1 0 0 0 0 0 0. This means that bit 6 is high (talk) and the primary address is zero. The \x22 stands for hex 22, which represents the binary pattern of 0 0 1 0 0 0 1 0. This means that bit 5 is high (listen) and the primary address is 2. The \x64 stands for hex 64, which represents the binary pattern of 0 1 1 0 0 1 0 0. This means that bits 6 and 5 are high -- so, treat the following address as a secondary address -- and the address is 4.