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 implementation
Goto page Previous  1, 2, 3, 4, 5, 6  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
anupama619



Joined: 10 Sep 2009
Posts: 47

View user's profile Send private message

PostPosted: Tue Jun 15, 2010 5:51 am     Reply with quote

I tried with the modifications you given.
Code:

#define USE_WITH_PC 1

#include <16f877a.h>
#device *=16
#device ADC=10            //For 10 bit ADC
#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 57600

#ifndef USE_WITH_PC
#use rs232(baud=57600, 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
#define DEBUG_MSG(msg) int i//fprintf(PC, msg)       changed here.....
#define DEBUG_DATA(msg,data) int j//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 0x01
//Added for rs485 communication
#define MODBUS_SERIAL_ENABLE_PIN   1   // Controls DE pin for RS485
#define MODBUS_SERIAL_RX_ENABLE    1   // Controls RE pin for RS485

But unfortunately it is not working.
What may be the main points I missed out??
Please help me
Thanks in advance
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Jun 15, 2010 6:23 am     Reply with quote

Could you describe with more details the architecture of your testings.
It is improbable that it works without a step by step debugging procedure, for this purpose a scope is mandatory.
Are the master able to transmit a single char? are the slaves able to receive? Are you using a monitoring tool? wich?
Tell us what does and what do not.

Humberto
anupama619



Joined: 10 Sep 2009
Posts: 47

View user's profile Send private message

modbus implementation using rs485
PostPosted: Wed Jun 16, 2010 12:07 am     Reply with quote

hi humberto,
Thanks for your cooperation.
Actually my code was working perfectly with rs232 interface.
But now I want to change it to rs485.
So I did only 1 modification in my code like this
Code:

#define MODBUS_SERIAL_ENABLE_PIN   1   // Controls DE pin for RS485
#define MODBUS_SERIAL_RX_ENABLE    1   // Controls RE pin for RS485

All other things are same. But unfortunately my slave is not receiving any single character. What should be the other modifications I need to do in order to shift the interface from rs232 to rs485.
Hoping a reply.
Thanks in advance
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Wed Jun 16, 2010 7:52 am     Reply with quote

Seems to be that your problem is in the hardware level. Forget the modbus for now and
try to do a transmission test in order to be able to monitor the data coming out of the Master.

Humberto
anupama619



Joined: 10 Sep 2009
Posts: 47

View user's profile Send private message

PostPosted: Thu Jun 17, 2010 2:06 am     Reply with quote

hi Humberto,
Thanks for your reply.
I tried RS485 communication with out modbus.
And my master able to transmit data successively.
Then I switched to modbus. And at that time also it sending some strings. So I connected my slave and tried. But unfortunately it is not receiving any data.
What might be the problem?
In my hardware I just shorted RE and DE pin of max485 and then connected it to PIN_B5 of my master (PIC16F877A). As you told in my code I am not taking care of PIN_B5.
More in the hardware I connected RX(PIN_C6),TX(PIN_C7) to RO and DI of MAX485. From there I connected D+,D- and ground to my slave.
What might be the problem?
Is it a hardware or software problem???
Hoping a reply.
Thanks in advance
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Thu Jun 17, 2010 6:28 am     Reply with quote

Quote:

More in the hardware I connected RX(PIN_C6),TX(PIN_C7) to RO and DI of MAX485.From there I connected D+,D- and ground to my slave.

NOP.
Rx PIN_C7 must be wired to transceiver R output.
Tx PIN_C6 must be wired to transceiver D input.

Humberto
anupama619



Joined: 10 Sep 2009
Posts: 47

View user's profile Send private message

modbus implementation
PostPosted: Sat Jun 19, 2010 5:26 am     Reply with quote

hi Humberto,
Thanks for your advice.
Now I changed my connection.
One more doubt what should be the hardware connection for DE and RE pin of Max485?As per code
#define MODBUS_SERIAL_ENABLE_PIN 1 // Controls DE pin for RS485
#define MODBUS_SERIAL_RX_ENABLE 1 // Controls RE pin for RS485

But in the hardware where I want to connect these enable pin?
Or how can I control DE and RE pin?To which pin I want to make DE and RE connection?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jun 21, 2010 3:59 pm     Reply with quote

This page has a schematic of the connections between the PIC and
the RS-485 driver chip:
http://www.mikroe.com/en/books/picbasicbook/09/rs485.gif
You must specify the PIC pin for the RS-485 enable signal in your
#use rs232() statement.

I don't say this will fix all your problems. I am just trying to help
you with this one small part of it.
anupama619



Joined: 10 Sep 2009
Posts: 47

View user's profile Send private message

modbus
PostPosted: Tue Jun 22, 2010 4:32 am     Reply with quote

Thanks for your advice.
I referred the schematic diagram. And I checked rs485 communication without modbus. The transmission and reception was working perfect. But when changed to modbus and then connected it to slave it is not working at all.
What may be the problem? I defined #use rs232 like this
Code:

#define RS485_ENABLE_PIN   PIN_B5   // Controls DE pin.  RX low, TX high.
#define RS485_RX_ENABLE    PIN_B5   // Controls RE pin.  Should keep low.

#define MODBUS_SERIAL_ENABLE_PIN   1   // Controls DE pin for RS485
#define MODBUS_SERIAL_RX_ENABLE    1    // Controls RE pin for RS485
     
#define MODBUS_TYPE MODBUS_TYPE_MASTER
#define MODBUS_SERIAL_RX_BUFFER_SIZE 64
#define MODBUS_SERIAL_BAUD 57600

#ifndef USE_WITH_PC

#use rs232(baud=57600, xmit=PIN_C6, rcv=PIN_C7, enable=RS485_ENABLE_PIN, stream=PC, errors)   //RS232 definition

#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
#define DEBUG_MSG(msg) int i//fprintf(PC, msg)       changed here.....
#define DEBUG_DATA(msg,data) int j//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

Hoping a reply
Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jun 22, 2010 12:18 pm     Reply with quote

Which one of these CCS files are you using as the basis of your program ?
Quote:

c:\program files\picc\examples\ex_modbus.c
c:\program files\picc\examples\ex_modbus_master.c
c:\program files\picc\examples\ex_modbus_slave.c
c:\program files\picc\drivers\modbus.c
anupama619



Joined: 10 Sep 2009
Posts: 47

View user's profile Send private message

modbus
PostPosted: Tue Jun 22, 2010 11:29 pm     Reply with quote

I am using
c:\program files\picc\examples\ex_modbus_master.c
and in that file I included modbus.c also.

And it is working fine with RS232 interface. Problem arises only when it changed to rs485 inteface. I checked the rs485 communication without modbus and it is working fine.
Hoping some help from you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 23, 2010 2:57 pm     Reply with quote

Is your modbus Master board connected to your PC, or is it
connected to a Slave modbus board ?

In other words, what is connected to your Modbus master board ?
anupama619



Joined: 10 Sep 2009
Posts: 47

View user's profile Send private message

modbus
PostPosted: Wed Jun 23, 2010 11:25 pm     Reply with quote

modbus master board connected to the modbus slave board.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 24, 2010 2:55 pm     Reply with quote

Why can't you do the connections exactly the way that CCS wants you
to do it the examples ? In Ex_Modbus_Master.c, they have the diagram
shown below. They want you to use pins B0 and B1.
Code:

////            PCH and PCM             
////    ----------     ----------       
////    |        |     |        |       
////    | Master |     | Slave  |       
////    |        |     |        |       
////    |      B1|---->|B0      |       
////    |      B0|<----|B1      |       
////    ----------     ----------     

So if you are using RS-485 drivers, they should be connected to pins B0 and B1. (Not C6 and C7).

I suggest that you follow the CCS examples exactly.
scrwld



Joined: 28 Jun 2010
Posts: 3

View user's profile Send private message

PostPosted: Mon Jun 28, 2010 2:29 am     Reply with quote

Hello everyone. I'm new to this forum.

I have the same problem, works with max232 and MAX485 does not work, take an inverter gate I had on hand (74HC14) and now works, no 100 percent.From my experience with modbus have never had to add some additional device to work.

continue to seek the reason for this when have some results I will indicate.

regards

luis lopez



http://www.subirimagenes.com/otros-pic16f877232485-4728280.html
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 5 of 6

 
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