본문 바로가기
Siemens Automation/TIAPortal STEP7

S7-1200 Modbus RTU Sample Program

by 의명 2020. 6. 6.

HARDWARE CONFIGURATION - S7-1200 & S7-1200 Modbus RTU Master-Slave 


Modbus RTU 통신의 사용시 Sample program  구성


S7-1200 Modbus RTU 구현을 위한 Library 는 별도의 S/W License 가 필요없음.

(기존 구형 PLC S7-300, S7-400 시리즈의 경우 별도의 S/W License 가 필요했지만 신형 PLC는 비용이 들지 않음)


1) Master PLC 의 project 를 생성한다.


1. Master PLC 의 Device configuration 에서 CM1241 (RS485 모듈) 의 설정


Port configuration



Hardware Identifier 확인



2. Master PLC  의 Sample Logic Programming


Modbus 통신시 주고 받을 데이터가 저장될 Global DB 를 생성한 후 아래와 같이 파라메터를 입력한다.



OB1 에서 Communication => Communication processor => Modbus => MB_COMM_LOAD 를 network 로 호출한 후 아래와 같이 파라메터를 할당한다.



EN : MB_COMM_LOAD 는 CPU 의 재기동시 한번만 인식되면 되기 때문에 EN 파라메터에는 '첫번째 cycle 에서만 On 되는 system memory bit 인 M1.0 을 할당한다. (System memory 는 Device configuration 의 CPU속성
System and clock memory' 에서 설정할 수 있다.
port : 하드웨어 번호
baud : 통신 속도
MB_DB : MB__Master 의 데이터가 저장되는 인스턴스 DB

MB_MASTER 를 호출하여 아래와 같이 프로그램을 작성한다.  (Modbus writing mode)


MB_Addr : Modbus rtu station 번호
Mode : Reading or Writing mode
Data Addr : Slave 측의 Modbus starting address
Data LEN : 쓰거나 읽어올 데이터의 개수
Data PTR : 마스터에서 슬레이브로 보낼 데이터 영역 혹은 슬레이브로부터 받는 데이터를 저장할 영역

Modbus step 구성


모드버스 스텝이 1일경우 DB3.DBW4 에 1 값을 더해준다
모드버스 스텝이 1일경우 MB_Master 의 Req 신호를 set 시킨다 ==> MB_Master 블록이 실행됨 (Slave 측에 데이터 writing or Slave 로부터 data reading)

STEP2 programming

모드버스 스텝이 1이고, MB_Master 의 done 신호를 받거나 error 신호를 받게되면 MB_Master 의 Req 신호를 Reset 시키고, 모드버스 스텝에 값을 2로 바꾼다
 ==> 모드버스 스텝 1이 정상적으로 처리되었거나 혹은 에러가 발생했더라도 모드버스 스텝에 값을 2로 바꾼다
 ==> Req 신호를 Reset 시키는것은 다음번 차례때 Req 신호를 Set 시킬수 있도록 만드는 준비 과정
 ==> 모드버스의 어느 한 채널? 에 문제가 생기더라도 계속적으로 다른 스텝을 진행할 수 있도록 만드는 회로

Modbus Reading mode  설정을 위해 다시 MB_MASTER 호출 후 파라메터 입력


모드버스 스텝이 2가 되면 위의 MB_Master 의 enable 조건이 충족된다.
Mode 0 : reading
Data_PTR : Slave 의 modbus 40003 으로부터 2개의 데이터를 가져와 DB3.DBX6.0 부터의 영역에 writing 한다


모드버스 스텝이 2일 경우 MB_Master 의 request 신호를 set 시킨다
 ==> 두개의 호출된 MB_Master 의 Req 신호가 모두 on 이 되지만 enable 조건이 모드버스 스텝의 현재값에 따라 틀려지기 때문에 문제없음
 ==> 두번째 호출된 MB_Master 가 실행된다


모드버스 스텝의 값이 2이고, MB_Master 의 done 신호가 On 되거나 error 신호가 들어오게 되면 MB_Master 의 req 신호를 reset 시키고,
동시에 모드버스 스텝의 값을 1로 바꾼다. ==> 다시 모드버스 스텝 1을 실행시킨다.



1) Slave PLC 의 project 를 생성한다.

1. Slave PLC 의 Device configuration 에서 CM1241 (RS485 모듈) 의 설정


CM1241 의 Hardware Identifier 를 확인


2. Slave PLC  의 Sample Logic Programming

Modbus 통신시 주고 받을 데이터가 저장될 Global DB 를 생성한 후 아래와 같이 파라메터를 입력한다.


OB1 에서 MB_COMM_LOAD 를 호출하여 다음과 같이 파라메터를 입력한다.


※ 참고사항
DB1번 안에 들어가서 보면 MODE 부분이 있는데 이 부분에 4번 으로 되어 있어야 읽고/쓰기가 가능하다. DB안에 적용이 안되어 있으면 통신이 안될 가능성이 큽니다.
  • 0 = Full duplex (RS232)

  • 1 = Full duplex (RS422) four-wire mode (point-to-point)

  • 2 = Full duplex (RS 422) four-wire mode (multipoint master, CM PtP (ET 200SP))

  • 3 = Full duplex (RS 422) four-wire mode (multipoint slave, CM PtP (ET 200SP))

  • 4 = Half duplex (RS485) two-wire mode 


MB_Slave 호출


통신으로 주고 받을 데이터의 연산을 위한 로직 구성


CB 1241 Connector Wiring

Biasing and terminating an RS485 network connector

Siemens provides an RS485 network connector that you can use to easily connect multiple devices to an RS485 network. 
The connector has two sets of terminals that allow you to attach the incoming and outgoing network cables. 
The connector also includes switches for selectively biasing and terminating the network.

Note
You terminate and bias only the two ends of the RS485 network. The devices in between the two end devices are not terminated or biased. 
Bare cable shielding: Approximately 12 mm (1/2 in) must contact the metal guides of all locations.


① Switch position = On: Terminated and biased

② Switch position = Off: No termination or bias

③ Switch position = On: Terminated and biased

Table: Termination and bias for the RS485 connectorRS485 connectortermination and bias


① Pin number
② Network connector
③ Cable shield

The CB 1241 provides internal resistors for terminating and biasing the network. 
To terminate and bias the connection, connect TRA to TA and connect TRB to TB to include the internal resistors to the circuit. CB 1241 does not have a 9-pin connector. 
The following table shows the connections to a 9-pin connector on the communications partner.

Table: Termination and bias for the CB 1241 CB 1241termination and bias
① Connect M to the cable shield
② A = TxD/RxD - (Green wire / Pin  8)
③ B = TxD/RxD + (Red wire / Pin 3)

CM 1241 Connector Wiring


1. 핀 2 및 9는 RS422에서 송신 신호로만 사용됩니다.
2. RTS는 TTL 레벨 신호이며 이 신호를 기준으로 다른 반이중 디바이스를 제어하는 데 사용할 수 있습니다. 사용자가 송신할 때 활성화되고 모든 다른 시간에 비활성화됩니다.
3. 일반적인 상황에서는 3번, 8번 Connection

지멘스 교육이나 기술지원이 문의 사항이 있으시면 언제든지 연락주시고,

제가 도움을 드릴 수 있는 내용은 최대한 답을 드릴수 있도록 하겠습니다.

긴글 읽어주셔서 감사드리고, 틈나는대로 계속 관련 내용 업데이트하도록 하겠습니다

감사합니다.





'Siemens Automation > TIAPortal STEP7' 카테고리의 다른 글

TSEND_C / TRCV_C SETTING  (0) 2020.06.13
I-DEVICE COMMUNICATION  (6) 2020.06.12
S7-1200 PID CONTROL  (3) 2020.06.05
S7-1200 CPU FIRMWARE UPDATE  (2) 2020.06.04
SIEMENS PLC SERIES (S7-1200, S7-1500)  (0) 2020.05.21

댓글