View previous topic :: View next topic |
Author |
Message |
mniknezhadi
Joined: 22 Jun 2011 Posts: 3 Location: IRAN
|
Modbus rtu |
Posted: Wed Jan 22, 2014 4:23 pm |
|
|
Dear experts,
I did a S7-200 SIEMENS PLC automation project by modbus rtu. I made some measuring devices by PIC18f4520 and conect them by modbus as slaves to PLC.
Slave codes are same as CCS ex_modbus_slave.c example. and I use the codes to read holding registers. so the starting address to catch the holdin registers should be 40001.
I read several times the ex_modbus_slave.c and modbus.c files but I didn't understand how the register address's defines to "40001,40002, ...." in these files. _________________ M.NIKNEZHADI |
|
|
Jerson
Joined: 31 Jul 2009 Posts: 125 Location: Bombay, India
|
|
Posted: Wed Jan 22, 2014 6:59 pm |
|
|
The initial 4 in the 40001 address indicates Read Holding Registers. So, the MODBUS PLC address ranges usually map to
1xxxx - Read Coil Status
2xxxx - Read Input status
3xxxx - Read / Write Holding Registers
4xxxx - Read / Writer Input Registers
In the modbus code, this 'initial digit' goes to the 'function code'. The rest of the 4 digits are the starting address.
Hope that helps |
|
|
mniknezhadi
Joined: 22 Jun 2011 Posts: 3 Location: IRAN
|
|
Posted: Wed Jan 22, 2014 11:43 pm |
|
|
Dear Jerson,
Thank you for your response.
It means the starting address puts in the modbus PDU. But how the "ex_modbus_slave.c / modbus.c" makes or determines it?
In fact I plan to manage the coils and inputs in PIC18f4520. I could manage the holding registers. but because the "ex_modbus_slave.c / modbus.c" example is based on PIC16F877, I am confused for Coils/inputs due to REGISTER FILE MAP differences of PIC16F877 and PIC18f4520. For example PORTA in PIC16F877 is mapped to "05h" and "F80h" for PIC18F4520.
May be I conflict the PIC's REGISTER FILE MAP and starting address in Modbus PDU. _________________ M.NIKNEZHADI |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Thu Jan 23, 2014 1:32 am |
|
|
Registers in the PIC have nothing to do with Modbus registers....
The Modbus registers refer to areas of RAM 'input_regs', and 'hold_regs' the code defines. It is the contents of these areas that are used for the Modbus communications.
On any bus like this, you would never talk directly to the registers of the chip. This would be a sure way of making the code crash.... |
|
|
mniknezhadi
Joined: 22 Jun 2011 Posts: 3 Location: IRAN
|
|
Posted: Fri Jan 24, 2014 6:35 am |
|
|
Dear Ttelmah,
Thank you for your directions.
As you wrote I forget the Modbus registers and I tried to manage the 'input_regs'.
It was a succsesful try. But I can't understand the folowing codes in 'ex_modbus_slave.c ':
Code: | void main()
{
int8 coils = 0b00000101;
int8 inputs = 0b00001001;
|
Are these codes acts as coils(outputs) and inputs like the PLCs?
If they are how I could manage them by a master device?
_________________ M.NIKNEZHADI |
|
|
|