Max232-RS232-TTL สื่อสาร Arduino Mega

ศึกษาการสื่อสารอนุกรมด้วยบอร์ดตัวแปลง RS232-TTL  รุ่น  Max232  ด้วยบอร์ด ArduinoMega2560
โดยใช้โค่ดตัวอย่างจาก  Link 
และติดตามผลด้วย Terminal Debugging Software

#define RS232PORT Serial3
#define USBPORT   Serial
#define RS232BAUDRATE  115200
#define USBBAUDRATE    115200
void setup()
{
  RS232PORT.begin(RS232BAUDRATE); // default is 8,N,1
  USBPORT.begin(USBBAUDRATE);
  // while (!SerialUSB);
  Serial.begin(115200);
}
void loop()
{
  byte cData[100];
  int nBytesAvail = 0;
  int nBytes = 0;
  if((nBytesAvail = RS232PORT.available()) >0)
  {
    // Read data into receive buffer
    nBytes = RS232PORT.readBytes(cData,nBytesAvail);
    // Write teh data to the other port
    USBPORT.write(cData,nBytes);
  }//end if
  // check for data from th eusb port
  if((nBytesAvail = USBPORT.available())>0)
  {
    // Read data into receive buffer
    nBytes = USBPORT.readBytes(cData,nBytesAvail);
    // Write the data to other port
    RS232PORT.write(cData,nBytes);
  } // end if
}// end loop

โค้ดนี้ทำงานอย่างไร
Serial Monitor ของ Arduino IDE จะทำหน้าที่รับข้อมูลทางช่อง Serial Input เมื่อกด Enter จะส่งข้อมูลจาก AtMega ออกทาง Serial Port 3 และ USBPort จะอ่านผลจาก RS232 Port และแสดงผลบน Terminal Software    โดยดาวน์โหลดซอฟต์แวร์ได้ที่นี่ครับ
 
ได้ผลตามคลิป