RS-485 Communication 구현

RS-485 Communication Line 구현



1. 현재는 UART로 통신하는 기계를 Noise Robustness와 N:N Communication을 위해서 hardware와 software를 구현하는 과정을 적는다.



2. 메인 통신 모듈은 Teensy 3.5 (pin 버젼)이며, RS-485 Transceiver는 SP3485의 Breakout 모듈을 사용한다.



3. Digikey Order 내역 (1~2주 정도 걸림)



- SP3485 Transceiver, RS-485 Interface Evaluation Board: 1568-1589-ND

Datasheet: https://www.sparkfun.com/datasheets/Components/General/sp3485CN-LTR.pdf
Schematics of the Module: https://cdn.sparkfun.com/datasheets/BreakoutBoards/RS485_Breakout_v10.pdf


RS-485 모듈
SP3485 Schematics


- Teensy 3.5: 1568-1464-ND

Datasheet1: Find MK64FX512VMD12 at NXP
Datasheet2: https://media.digikey.com/pdf/Data%20Sheets/Sparkfun%20PDFs/DEV-14056_Web.pdf

Tutorials:
https://www.pjrc.com/teensy/tutorial.html
https://www.pjrc.com/teensy/pins.html
https://www.pjrc.com/teensy/usb_debug_only.html


Teensy 3.5 with Hearders


Teensy 3.5 Pin Map (Frontside)


Teensy 3.5 Pin Map (Backside)


4. pySerial + Arduino


현재 회사에서 주로 사용하는 툴은 Arduino sketch이며, 본인이 사용하는 언어는 Python이라서 두 개를 동시에 개발해보자.


5. pySerial


class serial.Serial

__init__(port=None, baudrate=9600, bytesize=EIGHTBITS, parity=PARITY_NONE, stopbits=STOPBITS_ONE, timeout=None, xonxoff=False, rtscts=False, write_timeout=None, dsrdtr=False, inter_byte_timeout=None)¶

- Parameters:
port – Device name or None.
baudrate (int) – Baud rate such as 9600 or 115200 etc.
bytesize – Number of data bits. Possible values: FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS
parity – Enable parity checking. Possible values: PARITY_NONE, PARITY_EVEN, PARITY_ODD PARITY_MARK, PARITY_SPACE
stopbits – Number of stop bits. Possible values: STOPBITS_ONE, STOPBITS_ONE_POINT_FIVE, STOPBITS_TWO
timeout (float) – Set a read timeout value.
xonxoff (bool) – Enable software flow control.
rtscts (bool) – Enable hardware (RTS/CTS) flow control.
dsrdtr (bool) – Enable hardware (DSR/DTR) flow control.
write_timeout (float) – Set a write timeout value.
inter_byte_timeout (float) – Inter-character timeout, None to disable (default).
Raises:
ValueError – Will be raised when parameter are out of range, e.g. baud rate, data bits.
SerialException – In case the device can not be found or can not be configured.

open()
Open port.

close()
Close port immediately.

read(size=1)
Parameters: size – Number of bytes to read.
Returns: Bytes read from the port.
Return type: bytes

Read size bytes from the serial port.


write(data)
Parameters: data – Data to send.
Returns: Number of bytes written.
Return type: int
Raises SerialTimeoutException:
  In case a write timeout is configured for the port and the time is exceeded.


flush()

Flush of file like objects. In this case, wait until all data is written.

reset_input_buffer()

Flush input buffer, discarding all it’s contents.

Changed in version 3.0: renamed from flushInput()

reset_output_buffer()
Clear output buffer, aborting the current output and discarding all that is in the buffer.


Changed in version 3.0: renamed from flushOutput()

rts

Setter: Set the state of the RTS line
Getter: Return the state of the RTS line
Type: bool
Set RTS line to specified logic level. It is possible to assign this value before opening the serial port, then the value is applied uppon open().

dtr
Setter: Set the state of the DTR line
Getter: Return the state of the DTR line
Type: bool
Set DTR line to specified logic level. It is possible to assign this value before opening the serial port, then the value is applied uppon open().




Comments

Popular posts from this blog

AVR for Arduino/Atmel MCU

UART Communication