I know that we can use pin no.3 to send the data as a output in RS232. But I am just wondering that there is another way to send only the voltage 5v to the RS232 in a short
PIC Microcontroller with TTL interface used logic as follows:
Logic 1 == 5 volt.
Logic 0 == 0 volt.
Computer with RS232 interface used logic as follows:
Logic 1 == -3 volt until -25 volt.
Logic 0 == 0 until 25 volt.
For connecting device TTL logic to RS232 logic can used MAX232 IC. MAX232 will translate your TTL logic to RS232 Logic.
Another options - cheaper and simple, used TRANSISTOR for convert TTL logic to RS232 logic vice versa, look at http://www.kmitl.ac.th/~kswichit/ap275/ap275.htm for details.
If need send data without hardware handshaking, only need pin 2 (RX), pin 3(TX), pin 5(GND). If need handshaking, add pin 7(RTS) AND pin 8(CTS).
Transmitte data as follows:
serialPort1.Open();
serialPort1.Write("your data in here");
Receive data as dollows:
public Form1()
{
InitializeComponent();
this.serialPort1.DataReceived += new SerialDataReceivedEventHandler(this.serialPort1_DataReceived);
serialPort1.Open();
}
void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int i = 0;
string[] DataReceived;
while (serialPort1.BytesToRead > 0)
{
DataReceived[i] = Convert.ToByte(serialPort1.ReadByte()); // data already in here
i++;
if (i == int.MaxValue-1)
i = 0;
}
// Parsing your data in here
}
If just need toggle output, used pin 4 (DTR) OR pint 7(RTS).
serialPort1.DtrEnable = true;
ORserialPort1.RtsEnable = true;