MAX485¸¦ »ç¿ëÇÑ ½Ã¸®¾ó RS-485 ÄÁ¹öÅÍ ¸ðµâÀÔ´Ï´Ù. RS-485´Â RS232, RS422¿¡ ºñÇؼ ¸¹Àº µå¶óÀ̹ö/¸®½Ã¹ö¸¦ »ç¿ëÇÒ ¼ö ÀÖÀ¸¸ç, RS232°¡ Åë½Å °Å¸®°¡ 15mÀÓ¿¡ ºñÇØ, °Å¸®´Â 1.2Km±îÁö Àü´ÞÇÒ ¼ö ÀÖÀ¸¸ç, Åë½Å¼Óµµµµ 10Mb/s±îÁö Áö¿øÇÕ´Ï´Ù. ƯÈ÷, Àü¼Û¹æ½ÄÀº Half Duplex ¹æ½ÄÀ̶ó¼, ÇϳªÀÇ ¼±À» »ç¿ëÇÑ ´Ù¼öÀÇ ¸ðÅÍ Á¦¾î¸¦ À§ÇÑ ·Îº¸Æ¼Áî»çÀÇ ´ÙÀ̳ª¹Í¼¿ µî¿¡ »ç¿ëµÇ°í ÀÖ½À´Ï´Ù.
±¸µ¿ Àü¾Ð: 5V »çÀÌÁî: 44mm x 14mm
¾ÆµÎÀÌ³ë ¿ì³ë¸¦ »ç¿ëÇÏ¿© ´Ù¼öÀÇ ¸Þ°¡¿Í Åë½ÅÇÏ´Â ¹æ¹ý
RS485¸¦ »ç¿ëÇÏ¿© ¾ÆµÎÀÌ³ë ¸Þ°¡¿Í ÇÁ·Î¹Ì´Ï¿ÍÀÇ ¿¬°á¹æ¹ý
¸¶½ºÅÍ ¼Ò½ºÄÚµå
#include <SoftwareSerial.h>
#define SSerialRX 10 //RXÇÉ
#define SSerialTX 11 //TXÇÉ
#define SSerialTxControl 3 //TXÄÁÆ®·ÑÇÉ
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 13
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
int byteReceived;
int byteSend;
void setup()
{
Serial.begin(9600);
pinMode(Pin13LED, OUTPUT);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive);
// TxÄÁÆ®·ÑÀ» ÀÌ¿ëÇØ ¼ö½Å¹ÞÀ»Áö ¹ß½ÅÇÒ Áö¸¦ ±¸ºÐÇÕ´Ï´Ù.
// ¼ö½Å¸ðµå - LOW
// ¹ß½Å¸ðµå - HIGH
RS485Serial.begin(4800); // º¸µå·¹ÀÌÆ®¸¦ ¼³Á¤ÇÕ´Ï´Ù.
}
void loop()
{
digitalWrite(Pin13LED, HIGH); // »óÅ ǥ½Ã
if (Serial.available())
{
byteReceived = Serial.read();
digitalWrite(SSerialTxControl, RS485Transmit); // ¼Û½Å¸ðµå
RS485Serial.write(byteReceived); // µ¥ÀÌÅÍ Àü¼Û
digitalWrite(Pin13LED, LOW);
delay(10);
digitalWrite(SSerialTxControl, RS485Receive); // ¼ö½Å¸ðµå
}
if (RS485Serial.available()) //½½·¹À̺êÂÊ¿¡¼ ¼ö½ÅµÈ µ¥ÀÌÅÍ Ã³¸®
{
digitalWrite(Pin13LED, HIGH);
byteReceived = RS485Serial.read(); // µ¥ÀÌÅÍ ¼ö½Å
Serial.write(byteReceived);
delay(10);
digitalWrite(Pin13LED, LOW);
}
}
½½·¹ÀÌºê ¼Ò½ºÄÚµå
#include <SoftwareSerial.h>
#define SSerialRX 10 //Serial Receive pin
#define SSerialTX 11 //Serial Transmit pin
#define SSerialTxControl 3 //RS485 Direction control
#define RS485Transmit HIGH
#define RS485Receive LOW
#define Pin13LED 13
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
int byteReceived;
int byteSend;
void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600);
pinMode(Pin13LED, OUTPUT);
pinMode(SSerialTxControl, OUTPUT);
digitalWrite(SSerialTxControl, RS485Receive); // Init Transceiver
RS485Serial.begin(4800); // set the data rate
}
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
if (RS485Serial.available()) //¸¶½ºÅÍ¿¡¼ ¹ÞÀº µ¥ÀÌÅÍ Ã³¸®
{
byteSend = RS485Serial.read(); // ÀÐÀºµ¥ÀÌÅÍ ÀúÀå
digitalWrite(Pin13LED, HIGH); // »óÅ ǥ½Ã
delay(10);
digitalWrite(Pin13LED, LOW);
digitalWrite(SSerialTxControl, RS485Transmit); // ¼Û½Å¸ðµå
RS485Serial.write(byteSend); // ±×´ë·Î µ¹·ÁÁØ´Ù.
delay(10);
digitalWrite(SSerialTxControl, RS485Receive); // ¼ö½Å¸ðµå
}
}
|