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 support@ccsinfo.com

modbus

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



Joined: 29 Aug 2013
Posts: 9

View user's profile Send private message

modbus
PostPosted: Wed Sep 04, 2013 2:03 am     Reply with quote

Hi,
I'm new in ccs programming. I want to make a project using modbus to supervise some parameters (like voltage, current, power factor) from different devices.
I never use modbus yet, so please guide me & suggest related code.
Please reply early.....

I'm using 18fxxxx pic uc.
Ttelmah



Joined: 11 Mar 2010
Posts: 19358

View user's profile Send private message

PostPosted: Wed Sep 04, 2013 3:08 am     Reply with quote

Look at the examples....
jhon



Joined: 29 Aug 2013
Posts: 9

View user's profile Send private message

PostPosted: Thu Sep 05, 2013 12:13 am     Reply with quote

thx for reply...
jhon



Joined: 29 Aug 2013
Posts: 9

View user's profile Send private message

PostPosted: Sun Sep 15, 2013 12:26 am     Reply with quote

Hello,
I was looking at example of ccs as you recommended but there is a problem in understanding the code.

I'm using rs232 than rs485 for serial communication and in code modbus
initialization is given for rs485, so in that case how can i initialize modbus for rs232 ?

Again there is a problem in crc calculation function and exception.
Is there a necessity to include all exception as given in example ?
Plz reply to my question as early as possible.
Ttelmah



Joined: 11 Mar 2010
Posts: 19358

View user's profile Send private message

PostPosted: Sun Sep 15, 2013 1:03 am     Reply with quote

There is no difference between RS232, and RS485. They are 'signalling standards', not protocols. You'll notice that though talking over 'RS485', the code uses #USE RS232.
The only difference is that RS485, is normally wired to be 'half duplex', with the TX, and RX sharing the same wire 'pair', and the software having (therefore) to turn the transmit buffer on/off when needed.
The code will run 'as is' over RS232 (with a suitable transceiver).

Best Wishes
jhon



Joined: 29 Aug 2013
Posts: 9

View user's profile Send private message

PostPosted: Sun Sep 15, 2013 1:10 am     Reply with quote

so can i directly use function modbus_init() to initialize modbus ????
jhon



Joined: 29 Aug 2013
Posts: 9

View user's profile Send private message

PostPosted: Sun Sep 15, 2013 1:14 am     Reply with quote

One thing more I just forget to ask you.
Plese also give the answer of my remaining two other questions.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sun Sep 15, 2013 4:41 am     Reply with quote

Hi,

Do a forum search, Modbus has been discussed (literally) thousands of times!

The forum is NOT here to hold your hand, and wipe your nose. Start by doing some of your own research, and not by asking a million questions.

Finally, asking us to answer you "as early as possible" is a bit annoying. We are all just CCS compiler users here, volunteering our free time.

John
jhon



Joined: 29 Aug 2013
Posts: 9

View user's profile Send private message

PostPosted: Sun Sep 15, 2013 4:56 am     Reply with quote

thx for suggestion, next time i will keep in my mind.
Ttelmah



Joined: 11 Mar 2010
Posts: 19358

View user's profile Send private message

PostPosted: Sun Sep 15, 2013 9:09 am     Reply with quote

as a further comment, Modbus _requires_ the CRC. From the 'specification':

"Frame checking (LRC or CRC) must be applied to the entire message".

Note the 'must'. If your PC application is not able to generate the CRC (which is sounds as if you are saying), then you are not using Modbus.
This is why the PIC code includes such handling.
jhon



Joined: 29 Aug 2013
Posts: 9

View user's profile Send private message

PostPosted: Mon Sep 16, 2013 11:11 pm     Reply with quote

I'm just starting testing of modbus slave program, but i have problem is that I'm using rs232 for serial communication. So how can i decide serial enable and serial reception pin of microcontroller ?
In the example such pin are defined for rs485.

Again once I decided above pin, is there is need to define serial TX and serial RX pin of microcontroller, like given below....
Code:
#define MODBUS_SERIAL_TX_PIN PIN_C6   // Data transmit pin
#define MODBUS_SERIAL_RX_PIN PIN_C7  // Data receive pin

I'm using pic18fxxxx uc..

plz help me....
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Tue Sep 17, 2013 6:33 am     Reply with quote

Hi,

Ttelmah already answered you in the 5th posting of this thread!!

From the perspective of the PIC, 'RS232' and 'RS485' are identical, except that with RS485 an 'extra' pin is defined to control the data direction on the
bi-directional bus.

So, for RS232, you'll need to define a 'Tx' pin and an 'Rx' pin, but you can omit the 'Enable' pin definition. Of course, you'll want to take advantage of
the hardware UART in your PIC, so be sure to use the hardware Tx and Rx pins in your defines.

It seems like your questions are of a very basic nature for the (relatively) complex project you are undertaking. My recommendation would be to put
aside 'Modbus' for the time being, and experiment with simple serial communications between your PIC and your PC to get yourself familiar
with how this all works.....

In other words, learn to walk before you attempt to run!

John
jhon



Joined: 29 Aug 2013
Posts: 9

View user's profile Send private message

PostPosted: Tue Sep 17, 2013 10:47 pm     Reply with quote

Hi,
As you told me that, first I work on serial communication. So I already did exercise of serial communication...but I'm new for modbus so I asked basic question of modbus.

If I want to test the slave functioning of modbus I make pc as a master and pic as a slave, in that case I use "modbus poll" for testing purpose. But if I want to send query to read the input register then what will be the code in slave program ? Should I write code for read the input register or anything else ?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Sep 18, 2013 12:06 am     Reply with quote

Did you review the ex_modbus_slave example? It simulates a few inputs, registers etc. You can use it as
a template for a MODBUS slave connected to real hardware.
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