View previous topic :: View next topic |
Author |
Message |
jhon
Joined: 29 Aug 2013 Posts: 9
|
modbus |
Posted: Wed Sep 04, 2013 2:03 am |
|
|
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: 19552
|
|
Posted: Wed Sep 04, 2013 3:08 am |
|
|
Look at the examples.... |
|
|
jhon
Joined: 29 Aug 2013 Posts: 9
|
|
Posted: Thu Sep 05, 2013 12:13 am |
|
|
thx for reply... |
|
|
jhon
Joined: 29 Aug 2013 Posts: 9
|
|
Posted: Sun Sep 15, 2013 12:26 am |
|
|
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: 19552
|
|
Posted: Sun Sep 15, 2013 1:03 am |
|
|
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
|
|
Posted: Sun Sep 15, 2013 1:10 am |
|
|
so can i directly use function modbus_init() to initialize modbus ???? |
|
|
jhon
Joined: 29 Aug 2013 Posts: 9
|
|
Posted: Sun Sep 15, 2013 1:14 am |
|
|
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
|
|
Posted: Sun Sep 15, 2013 4:41 am |
|
|
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
|
|
Posted: Sun Sep 15, 2013 4:56 am |
|
|
thx for suggestion, next time i will keep in my mind. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Sun Sep 15, 2013 9:09 am |
|
|
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
|
|
Posted: Mon Sep 16, 2013 11:11 pm |
|
|
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
|
|
Posted: Tue Sep 17, 2013 6:33 am |
|
|
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
|
|
Posted: Tue Sep 17, 2013 10:47 pm |
|
|
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
|
|
Posted: Wed Sep 18, 2013 12:06 am |
|
|
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. |
|
|
|