View previous topic :: View next topic |
Author |
Message |
anupama619
Joined: 10 Sep 2009 Posts: 47
|
Modbus implementation |
Posted: Sat Sep 12, 2009 6:36 am |
|
|
I want to implement modbus for interfacing HMI with pic16f877a. Which compiler is good for this application? Can I get any sample code? Thanks in advance. ![Embarassed](images/smiles/icon_redface.gif) |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
MODBUS Imp |
Posted: Sat Sep 12, 2009 6:04 pm |
|
|
CCS has a couple of modbus examples supplied with the the compiler when you buy it.
They should be helpfull.
Cheers. |
|
![](templates/subSilver/images/spacer.gif) |
anupama619
Joined: 10 Sep 2009 Posts: 47
|
Thanks for your help in modbus implementation..... |
Posted: Mon Sep 14, 2009 12:33 am |
|
|
First of all thanks for your reply. I successfully implemented modbus send. Now I am able to write my data into the HMI. But now I am facing a problem in response reception. So I couldn't perform the read operation also. I tried communication with interrupt and without interrupt also. Can anybody help me? Thanks in advance. ' ' |
|
![](templates/subSilver/images/spacer.gif) |
anupama619
Joined: 10 Sep 2009 Posts: 47
|
modbus implementation.... |
Posted: Tue Sep 15, 2009 5:37 am |
|
|
i tried modbus operations with ccs compiler example code....but i am not getting the output......can anybody help me.....because of this reason my project got stuck....plz help me...plz.....plz.......thanks in advance........' ' |
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Sep 15, 2009 7:16 am |
|
|
I can tell, that the CCS MODBUS master example is basically working. May be, there are some minor bugs, I don't remember exactly.
The first step is to check, if your request is understood and answered by the slave. This is less than receiving the response correctly. If you see a response, e.g. with a serial protocol monitor or MODBUS test software, then you can test, why it's possibly not received at the master. Dumping the received data bytes and checking it against the MODBUS specification is the usual way. |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
modbus implementation |
Posted: Tue Sep 15, 2009 8:01 am |
|
|
Thanks for your reply....i will try this now..... |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
modbus implementation... |
Posted: Tue Sep 15, 2009 8:25 am |
|
|
Thank you for your reply...But it still not working....I am using pic16f877a and for HMI application....Is EX_MODBUS_MASTER.C applicable for this?
And I used device monitoring studio as a simulator for verifying the serial data...but unfortunately I could not able to receive any data. |
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Sep 15, 2009 2:37 pm |
|
|
HMI application is very general. I guess, you know that it's using MODBUS protocol, but there are several other parameters to fit. I suggest to use a commercial or freeware MODBUS test software to communicate with the slave and then try to reproduce it's operation with your MODBUS master.
In my opinion, ModBusView from ocean controls is a simple and straightforward tool. It's not free, but evalution mode is sufficient to perform basic tests.http://www.oceancontrols.com.au/modbus/modview.htm
Generally, it's no problem to write a MODBUS application from the scratch, only using the protocol specifications from MODBUS.org, I did it several times with different platforms and programming languages. |
|
![](templates/subSilver/images/spacer.gif) |
anupama619
Joined: 10 Sep 2009 Posts: 47
|
modbus implementation |
Posted: Wed Sep 16, 2009 3:26 am |
|
|
Thanks for your replay..Previously i tried with mtester as master simulator and i succeeded in communication with the HMI...So I taken the same data and send it by my PIC...And i succeeded in modbus send but that was with mikroc compiler ..There i faced response reception problem...Because of this reason i changed my compiler . Now i am working with CCs compiler and with its examples.....But unfortunately i am not getting any results...Anyway as your opinion i will try with ModbusView modbus master slave simulator.... ' ' |
|
![](templates/subSilver/images/spacer.gif) |
anupama619
Joined: 10 Sep 2009 Posts: 47
|
modbus implementation |
Posted: Wed Sep 16, 2009 5:15 am |
|
|
I tried with ModbusView master-slave simulator and it is working fine...But when reproducing the same data with my program I could't able to receive the response..So the read operation also not working ....Can you please help me....The write operation was working fine..I given a 500ms start bit and 1ms between each characters...Is delay is required for response reception?????What is my problem in response reception????? I am using a baud rate of 9600,8 data bits,parity-none,...Can you please help me!!! I am trying with this For the last 2 weeks ....please help me....thanks in advance.......... ' ' |
|
![](templates/subSilver/images/spacer.gif) |
anupama619
Joined: 10 Sep 2009 Posts: 47
|
modbus implementation |
Posted: Wed Sep 16, 2009 6:33 am |
|
|
With modbusView simulator i am getting the following sequence.......I am using ex_modbus_master.c and i compiled with ccs compiler......Downloaded the hex file to PIC16F877A which is my master...........
[F0][00][F0][F0][F0][F0][00][00][00][00][00][F0][F0][F0][F0][F0][F0][F0][F0][00][00][F0][F0][F0][00][F0][00][F0][F0][F0][00][F0][00][F0][F0][00][00][00][00][00][00][00][F0][F0][00][00][F0][F0][00][F0][F0][F0][00][00][F0][00][00][F0][00][F0][00][00][F0][F0][00][F0][F0][00][F0][F0][F0][00][F0][F0][00][F0][00][00][F0][00][00][00][00][F0][00][00][F0][F0][00][F0][F0][00][F0][F0][00][F0][00][F0][00][00][F0][00][00][00][F0][F0][00][F0][F0][00][F0][00][F0][F0][00][00][00][F0][00][F0][F0][F0][00][00][00][F0][F0][F0][F0][F0][F0][F0][F0][00][00][F0][00][00][F0][00][F0][F0][00][F0][F0][00][F0][00][F0][00][F0][00][F0][F0][00][00][F0][00][00][00][F0][F0][00][00][F0][00][F0][F0][00][F0][F0][F0][00][00][00][00][00][F0][F0][F0][F0][00][F0][F0][00][F0][00][00][F0][00][00][F0][00][F0][00][F0][F0][F0][00][F0][F0][00][F0][F0][F0][F0][F0][00][F0][F0][00][F0][F0][F0][00][F0][00][F0][00][F0][F0][00][F0][00][F0] |
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Sep 16, 2009 7:55 am |
|
|
I don't clearly see which signal is displayed here. If it's the PIC Tx signal, I wonder if the baudrate is correct. |
|
![](templates/subSilver/images/spacer.gif) |
anupama619
Joined: 10 Sep 2009 Posts: 47
|
modbus implementation |
Posted: Wed Sep 16, 2009 8:13 am |
|
|
Thanks for your corperation....
This stream i got from the modbbus communication window..the transmit part was empty...and the receive part have the following stream...
[00][F0][00][00][F0][F0][F0][F0][F0][00][F0][F0][00][F0][F0][00][F0][F0][F0][00][F0][00][00][00][00][00][F0][F0][F0][F0][00][00][00][00][00][F0][00][F0][F0][00][F0][00][00][F0][F0][F0][F0][F0][00][F0][F0][00][F0][F0][F0][F0][F0][F0][F0][00][00][F0][00][00][00][00][F0][00][00][00][F0][00][F0][F0][F0][F0][00][F0][00][F0][F0][00][00][00][00][00][00][00][00][00][F0][F0][F0][00][F0][F0][00][F0][F0][00][F0][F0][F0][00][F0][00][F0][F0][F0][F0][00][F0][00][00][F0][F0][00][F0][00][00][00][F0][F0][F0][F0][F0][00][00][00][00][00][F0][F0][00][00][F0][00][00][F0][00][00][F0][00][00][00][F0][00][00][00][00][00][00][F0][00][00][00][00][00][00][00][00][00][00][00][00][F0][F0][00][00][F0][00][F0][00][00][00][F0][00][00][00][F0][00][F0][F0][F0][F0][00][F0][00][F0][F0][00][00][F0][00][00][F0][F0][F0][F0][00][F0][F0][F0][F0][F0][F0][00][F0][F0][F0][F0][F0][F0][F0][F0][00][F0][F0][00][00][F0][00][F0][F0][F0][F0][F0][F0][F0][F0][F0][F0][F0][F0][F0][00][F0][00][F0][F0][00][00][F0][F0][F0]
hoping a replay...
thanks in advance |
|
![](templates/subSilver/images/spacer.gif) |
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Sep 16, 2009 10:26 am |
|
|
What's the hardware connection? RS232/RS485
Can you show the UART setup at the PIC side? #fuses, #device r232(), pin connections to the RS232/RS485 driver |
|
![](templates/subSilver/images/spacer.gif) |
anupama619
Joined: 10 Sep 2009 Posts: 47
|
modbus implementation |
Posted: Wed Sep 16, 2009 11:57 pm |
|
|
I am using RS232 for communication and I used the ex_modbus_master.c, given in the ccs compiler example program.
This is the preproccessor part of that program.
Code: |
#include <16f877a.h>
#device *=16
#fuses HS, NOWDT, NOLVP, NOBROWNOUT, NOPROTECT, PUT
#use delay(clock=20M)
#define MODBUS_TYPE MODBUS_TYPE_MASTER
#define MODBUS_SERIAL_RX_BUFFER_SIZE 64
#define MODBUS_SERIAL_BAUD 9600
#ifndef USE_WITH_PC
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=PC, errors)
#define MODBUS_SERIAL_INT_SOURCE MODBUS_INT_EXT
#define MODBUS_SERIAL_TX_PIN PIN_B1 // Data transmit pin
#define MODBUS_SERIAL_RX_PIN PIN_B0 // Data receive pin
//The following should be defined for RS485 communication
//#define MODBUS_SERIAL_ENABLE_PIN 0 // Controls DE pin for RS485
//#define MODBUS_SERIAL_RX_ENABLE 0 // Controls RE pin for RS485
#define DEBUG_MSG(msg) fprintf(PC, msg)
#define DEBUG_DATA(msg,data) fprintf(PC, msg, data)
#else
#define MODBUS_SERIAL_INT_SOURCE MODBUS_INT_RDA
#define DEBUG_MSG(msg) if(0)
#define DEBUG_DATA(msg,data) if(0)
#endif
#include "modbus.c"
#define MODBUS_SLAVE_ADDRESS 0xF7
|
Hoping a reply....
Thanks in advance. |
|
![](templates/subSilver/images/spacer.gif) |
|