There are many ICs that use a two wire serial protocol to communicate with other chips. This bus (which often goes by the name I2C, IIC, SMBUS, etc.) has a single data and a single clock line. You can connect a large number of devices to a single bus, and it is even possible to have multiple masters that share slave devices on the bus.

The GP-7 kit allows your PC to communicate with these devices easily. You can use the GP-7 to test serial bus devices, or you can take advantage of the wide array of converters and sensors that use this popular protocol.

As an example, consider an LM76 temperature sensor. These chips are mainly used in PC motherboard applications where they monitor a temperature and shut down power if the temperature reaches a certain set point. These aren't expensive (a couple of bucks in singles) although they are surface mount parts.

The LM76 has two pins that are used to set the bus address of the device (A0 and A1). The 7 bit address is always 1001000 + the two bits formed by A1 and A0. So if A1 and A0 are tied high (as they are in my example) the bus address is 1001011. For the GP-7, of course, this is left-justified in the GP-7's address byte so that the address used with the GP-7 is actually 10010110 or, written in hex, 96.

The LM76 only has 8 pins, and of those, two are not needed in this application. Of course, you need power on pin 8 (I used an LM76-CMH5 which requires 5V) and ground on pin 4. In addition, I tied pins 7 and 6 to 5V to set the address, as mentioned above. Finally, pin 1 (SDA) goes to the the GP-7's data line and pin 2 (SCL) connects to the GP-7's clock line.

The program shown above communicates with the GP-7 (and thereby with the LM76) to read the temperature. The entire program is pretty simple (although it does assume the GP-7 is on COM1):

Private Sub C_Click()  ' Convert to Centigrade
F.Value = False
Timer1_Timer  ' Force update
End Sub

Private Sub F_Click() ' Convert to F
C.Value = False
Timer1_Timer ' Force update
End Sub

' Initialize a few things
Private Sub Form_Load()
I2CA.PortOpen = True   ' open the serial port
I2CA.Address = &H96    ' LM76 address
C.Value = True         ' select C 
End Sub

' Every second, do the following:
Private Sub Timer1_Timer()
I2CA.Data = Array() ' no data to send
I2CA.Receive 2      ' read 2 bytes
t = I2CA.Data(0) * 256 + I2CA.Data(1)
I2CA.BusStop  ' be sure to let chip read data again
t = t / 8 * 0.0625 ' convert to C
If C.Value = True Then
    Temp.Caption = Format(t, "##.0C")
    Temp.Caption = Format(t * 9 / 5 + 32, "##.0F")
End If
End Sub

That's it! Of course, you could add code to select a different COM port, if you wanted. Also, if you wired A0 and A1 differently, you could use up to 4 different LM76s and read each one. Naturally, you can also mix and match other two wire devices on the same bus as long as the addresses are different.

Here's the files for the above example: Don't forget to register the awc.ocx file (use "regsvr32 awc.ocx") so that your system can find the ActiveX control.

Site contents © 1997-2018 by AWC, Houston TX    (281) 334-4341