Hi. Welcome to channel Factonation. This is the episode 3 of the VDO series teaching the foundation of MODBUS RS485. Our main task today is to configure 2 Amsamotion brand PLCs to perform a handshake in the RS485 network. RS485 is the network that requires the wiring of 2 electrical wires. We have already mentioned in earlier episodes that RS485 can create a network communication on the system. There are 2 terminals: + and -. Or we can also call them A and B or D+ and D- depending on the manufacturers' nomenclature. However, the important point is to connect the devices using 'multidrop' configuration, which means + will always have to connect to + all along the chain. Likewise, - will always have to connect to - all the way throughout the whole system. After connecting all the devices, we need to configure the settings which contain at least 4 main parameters to be set to the same value The first parameter is Baud rate which determines the speed of data transfer with the unit in Bits per second. We might be familiar with values like 1200 bps, 2400 bps, 4800, 9600 and so on. The second parameter is Number of Data bits or the number of bits which contains in the 'Data' section in the data frame message being communicated. It can be either 7 or 8. The third parameter is Number of Stop bits or the number of bits at the end of frame in the RS485 data frame communication. It can be either 1 or 2. The last parameter is Parity which is the parameter for error checking in serial communication (non-odd/even). Now the important part is to make sure all devices have the same RS485 port settings. All the earlier mentioned parameters have to be set the same in order to communicate successfully among devices via RS485 network So how can we know how exactly to set the parameter port setting? The answer is we need to look into the manual provided by devices' manufacturers. The manufacturer of the RS485 compatible devices always provide the information of how to configure the port settings For AMSAMOTION, you will find it in their manual. Even though, the manual is in Chinese, but you should be able to guess what is what. For the PLC which we want to make them the MODBUS 'Master', we will have to transmit the hexadecimal data to the address D8400. When we convert the hexadecimal number to binary, it will be 0s and 1s. The manual will state which bit digit will set the value of which parameter. For example, the 0th bit is the Number of data bits and if you set the 0th bit to 1, it means that Number of data bit is 8 bits. Next, the 1st and 2nd digit bit define Parity which the value here is 00. Hence it means None. You will also see that there is no choice available to choose either odd or even here, so it has to be none. The 3rd digit bit defines Number of stop bit. If the 3rd digit is 0, the Number of stop bit will be 1. And here u see 0 in the 3rd digit bit. The 4th, to 7th digit decide the Baud Rate for example if the value of these digits are 1000, it means the Baud Rate is 9600 For the 8th bit digit, if it is set as 1, it means we are using MODBUS protocol For the 9th bit digit, it decides if we are using RTU or ASCII. And as we are using RTU, we will set the 9th digit value to 0. The other bit digits just leave them as they were in default settings. Now we will put together all the bit digits in the right order and covert it from binary to hexadecimal number we will have 'H181' which is the parameter of this kind of setting. For the slave device, almost everything is the same except the hexadecimal address which will be D8420 instead of D8400 (in master's end) As other configurations are the same, so we will just move the value of H181 in first. Let's start together step by step. Open GX Works2. While waiting for the program, please unbox your PLCs and connect them to the 24V power source. After that, let's look at the input ports. For AMSAMOTION RS485, the input ports will be defined as D+ and D- Then I will use these 2 wires (Red and Yellow) to connect the PLCs with multi-drop connection which is to connect + to + and - to - let's do this now while waiting for the program. The best practice when connecting 2 wires near each other is to twist them together so that the electromagnetic fields will cancel out and reduce the effect of noises on the line Now let's go back to software. We will start by creating new project which is FX3U at master's end. Ok. Now that I have the new project, we will start with compiling. Then use the auxiliary relay M8411; a special coil that will turn on once the PLC turns on and then turn off right away. So it is suitable for initial value configuration like port setting. As mentioned earlier, we will have to move the hexadecimal value H181 to the address D8400 for master's PLC. So that's all for master's PLC. And I will save the file name as master. Then I will open another GX Works2 for slave's PLC. And as before, open new project, select FX-CPU, FX-3U Again, as before, use M8411 and move the value H181 to address D8420 for slave's setting And save the file name as 'slave' Now we have finished setting the parameters for RS485 port setting for both Master's PLC and Slave's PLC Now let's look at MODBUS messaging: it communicates in cycle or what we call 'Request-Response Cycle' which means that the command will be broadcasted into the network then slaves will determine if they have to respond to that command of not if they have to respond, they will proceed with the command and send the value back to master PLC. This messaging will happen in cycle. Next, we will have to define which PLC is master and which PLC is slave In this case, the manual says that for Master, we should MOV the value 1 to D8200 And for Slave, we should MOV the value 2 to D8200 Now let's return to the program. On the left, as it is for master, I will MOV value 1 to D8200 and for Slave, I will MOV the value 2 to D8200. And this is how to configure which one is the master and which is the slave Next, we should define the unit ID. As mentioned earlier, the MODBUS RS485 network can include up to 32 devices So to differentiate 1 device from another, we need to uniquely set the Unit ID to each device, like the concept of IP address In this case, I will set the MODBUS unit ID of master as 0 and of the first slave as 1 which in the manual states that to define the MODBUS Unit ID for master, we have to send the value to D8414 and for slave, we have to send the desired unit ID to D8434 now let's do that together. Start with MOV Unit ID 0 to D8414 for master and for slave, I will MOV the value 1 to D8434 as stated in the manual and compile. Now we have done with setting parameter, defining the master and slave PLC and setting unit IDs of both master and slave. Actually, we are almost done now. Only some minor configurations like request time out, or the number of retries. These following codes, you do not have to understand in details, you can just follow my lead here and can always use this code as default setting afterwards. I have input the comments to each code line. As you can see they are all that we have done so far; port setting, Master/Slave, Unit ID And those are the upper 3 lines in the program. In addition, you will see extra code lines which I set according to the PLC manual for other minor configurations ex Response Timeout, Delay Interval or Retries (number of times to reconnect) You can just follow the codes written here in case you use AMSAMOTION brand PLC but for those who use different brands, please refer to your manual for these minor configurations. See how to configure so that the network can perform handshake. For those who use AMSAMOTION brand, the code is already completed for both Master and Slave For the next episode, we will learn more about protocol memory map, function and also try sending MODBUS messages together. So see you in the next episode! Please like the VDO and subscribe to our channel for more content like this. Thanks :)