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

Help with MODBUS and 485

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



Joined: 10 Apr 2013
Posts: 4
Location: Venezuela

View user's profile Send private message

Help with MODBUS and 485
PostPosted: Tue Jan 07, 2014 9:34 am     Reply with quote

Hello

I'm already working with Modbus on pic (PC as Master and PIC as Slave).
The problem I have is that when i'm sending the response to the master it doesn't receive any valid frame, i mean i don't know why but the pic is sending some kind of "trash bytes" and i don't know how but those bytes are between my frame bytes.

I'm sending this: TX: 21 04 00 02 00 00 56 AA
PC is receiving this: RX:



I hope you can help me.
Wink
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Jan 07, 2014 10:02 am     Reply with quote

Missing pull-up/-down resistors on RS485?
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Jan 07, 2014 10:10 am     Reply with quote

FvM wrote:
Missing pull-up/-down resistors on RS485?


or missing the bus terminating resistor?
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
mikavamp



Joined: 10 Apr 2013
Posts: 4
Location: Venezuela

View user's profile Send private message

PostPosted: Tue Jan 07, 2014 10:12 am     Reply with quote

Hi
Between A-B pins 120ohm resistor
In A-680 ohm resistor to VCC and in B-680ohm resistor to 0V
mikavamp



Joined: 10 Apr 2013
Posts: 4
Location: Venezuela

View user's profile Send private message

PostPosted: Tue Jan 07, 2014 11:36 am     Reply with quote

I've changed the baud rate to 1200 and now I can see my full frame but right after the next poll I can see all those invalid bytes again.

Even if I received the valid frame the software returns an error. I don't know why is this happening. I've tried testing with other similar software and it happens the same thing.


Help please :(
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Jan 07, 2014 11:40 pm     Reply with quote

mikavamp wrote:
I've changed the baud rate to 1200 and now I can see my full frame but right after the next poll I can see all those invalid bytes again.

Even if I received the valid frame the software returns an error. I don't know why is this happening. I've tried testing with other similar software and it happens the same thing.


Help please :(


What happens when you remove the PIC and just have the PC transmit on the bus?

How are you driving the RS485 enable line on your PIC?
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
mikavamp



Joined: 10 Apr 2013
Posts: 4
Location: Venezuela

View user's profile Send private message

PostPosted: Wed Jan 08, 2014 12:25 am     Reply with quote

Thanks for answering

Well, without the PIC I can't see any response (not even invalid bytes).
==>TX: 21 04 00 00 00 01 36 AA
==>TX: 21 04 00 00 00 01 36 AA

If the PIC is connected but the rda interrupt is disable, the PC receives all those invalid bytes
==>TX: 21 04 00 00 00 01 36 AA
==>RX: FF FF FB FE FF

And when the interrupt is enable it receives the valid frame and the invalid bytes.
==>TX: 21 04 00 00 00 01 36 AA
==>TX: 21 04 00 02 ff fb 56 fe


And this is the code I'm using to enable the 485_tx/rx :

Code:
if ((tramaok==1)&&(slave==1))
   {
      output_high(pin_b5); //PIN_B5 enable 485_TX/RX
      delay_ms(10);
      for (b=0;b<8;b++)
      {
      fprintf(plc,"%c",envio[b]);
      }
      output_low(pin_b5);
      enable_interrupts(int_rda);     
   }


---------------------------------------------------------
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Thu Jan 09, 2014 9:50 am     Reply with quote

You may be disabling the RS485 line driver before the serial interface has serialized out the last bits of the last byte. In this case you device you are talking to will see a malformed MODBUS packet - been there, done that.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
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