After studying about communication with data or controlling output devices through Serial Port. In this part, We will learn about programming by Visual Basic through Serial Port for using programming to communicate with Bus system I2C (Inter Integrated Circuit ). You can find more information here http://www.esacademy.com/faq/i2c/.

Why do you have to use this system? Because there will be communication between IC and Module that can order or communicate in many and a long distance that have receiver and sender, the main module or Master to control all working in the system. For another module that is Slave will be controlled. The working of couple modules in this system, will be controlled by 2 signal lines, they have data line and signal line clock in order to use in setting rhythm of working. For taking devices or modules to connect in this system, it can be done by taking module to parallel, will use pressure level of electrical resource in each module will not be equal.

However, there will be Resistor as Pull Up at electrical resource for module and I recommend that you should put resistor at data signal and signal line clock in order to protect affecting by spasms that is mixed with electricity of module Resistor. Resistor as Pull is about 1kOhms. Let’s see the picture below.

Picture 1 module connection in communication as I2C

Well, how does it know each module that connects in parallel? In each module will have Address in different position that use code in setting status of Logic at legs of address signal of each module. Also, there will be an agreement between modules on pathway of connection as I2C, maybe use Protocol. Signal of I2C system will be divided into 2 lines,

1. SDA (Serial data Line)
2. SCL (Serial Clock Line)

Next, I want to show you a table of IC that is used in I2C Bus system.

Table 1 The type of IC that is used in I2C Bus system.

The type of IC

The example of number

The example of number

The example of number


For circuit that is used in changing signal from Serial Port to the signal that is I2C Bus system, will change SDA signal and SCL signal. This circuit will use Transistor, the type of NPN and connect as Open Collector, but Transistor should be the type that is used in high frequency. Let’s see the circuit below.


Picture 2 the form of circuit that change Serial Port signal to communicate with I2C system


Programming for connection to control signal with I2C Bus

Start to program in order to connect through I2C that. Let’s see above circuit, you will see that there is signal that is connected from Com Port of computer with I2C system. It has DCD(Pin 1),RTS(Pin7),DTR(Pin4) and Gnd(Pin5). In programming with Visual Basic will use controller named MS Comm 6, is the tool to control or get signal that come from Com Port

Table 2 The command of programming to control signal on I2C Bus system.

Serial Port(Com Port)

I2C Bus

DTR is logic 1

SCL is logic 1

MS Comm.DTREnable=True

DTR is logic 0

SCL is logic 0

MS Comm.DTREnable=False

RTS is logic 1

SDA is logic 1

MS Comm.RTSEnable=True

RTS is logic 0

SDA is logic 0

MS Comm.RTSEnable=False

For programming to verify signal line of DCD, we will use Properties named CDHolding of controller MS Comm 6 that will give the status as False and True. We may use condition to verify that is logic “0″ or1″, for example,

If MSComm.CDHolding = True Then
Debug.Print “logic
1″
Else
Debug.Print ” logic
0″
End If

Table 2 the protocol of controller and verify status of I2C Bus system.

The status of system

signal SDA(Data)

signal SCL(Clock)

Start signal

Logic changed from 1–>0

Logic changed from 1–>0

Stop signal

Logic changed from 0–>1

1

Send logic information0″

0

Logic changed from 1–>0

Send logic information1″

1

Logic changed from 1–>0

Feedback information

1

Logic changed from 1–>0

Working (Busy)

1

1


From seeing the table, you see 3 columns, the status of system; SDA signal and SCL signal that the writer concludes the step of communication in I2C bus system. You will notice that in each line at columns named “SDA signal”, and “SCL signal” are writed that “Logic changed from
1–>0” or “Logic changed from 0–>1”. In programming, let’s arrange the order of column is “SDA signal”, “SCL signal”. So, in creating signal, each status of system can be written in Visual Basic like the following,

For examples,

1) Start signal = SDA signal “Logic changed from 1–>0″ and SCL signal “Logic changed from 0–>1″

Sub Start_I2C()
MS Comm.RTSEnable=True SDA signal , logic as
1
MS Comm.DTREnable=True SCL signal, logic as
1
MS Comm.RTSEnable=False SDA signal , logic as 0
MS Comm.DTREnable=False SCL signal, logic as
0
End Sub

2) Stop signal = SDA signal ” Logic changed from 0–>1″ and SCL signal ” Logic changed from 1″

Sub Finish_I2C()
MS Comm.RTSEnable=False SDA signal , logic as 0
MS Comm.DTREnable=True SCL signal, logic as
1
MS Comm.RTSEnable=True SDA signal , logic as 1
End Sub

3) Send logic information0″= SDA signal ” Logic changed from 0″ and SCL signal ” Logic changed from 1–>0″

Sub Out0_I2C()
MS Comm.RTSEnable=False SDA signal , logic as 0
MS Comm.DTREnable=True SCL signal, logic as
1
MS Comm.DTREnable=False SDA signal , logic as
0
End Sub

4) Send logic information1″= SDA signal ” Logic changed from 1″ and SCL signal ” Logic changed from 1–>0″

Sub Out1_I2C()
MS Comm.RTSEnable=True SDA signal , logic as
1
MS Comm.DTREnable=True SCL signal, logic as 1
MS Comm.DTREnable=False SCL signal, logic as
0
End Sub

Finally, I hope you understand about this. You must have knowledge about hardware or I2C Bus system. If you will program like this, you must know values of computer system that hardware has so that software can communicate. Importantly, you should know the fundamental of Visual Basic programming communicated with Serial Port.

The content I mention, I just conclude how to program to communicate on I2C Bus system. For more information, you can search from internet.

Tags: plc
pac
pc
port
vb
vc
c#
parallel
serial
com
usb