CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Modbus rtu

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mniknezhadi



Joined: 22 Jun 2011
Posts: 3
Location: IRAN

View user's profile Send private message Yahoo Messenger

Modbus rtu
PostPosted: Wed Jan 22, 2014 4:23 pm     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Wed Jan 22, 2014 6:59 pm     Reply with quote

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

View user's profile Send private message Yahoo Messenger

PostPosted: Wed Jan 22, 2014 11:43 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jan 23, 2014 1:32 am     Reply with quote

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

View user's profile Send private message Yahoo Messenger

PostPosted: Fri Jan 24, 2014 6:35 am     Reply with quote

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?


Question
_________________
M.NIKNEZHADI
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group