View previous topic :: View next topic |
Author |
Message |
mikavamp
Joined: 10 Apr 2013 Posts: 4 Location: Venezuela
|
Help with MODBUS and 485 |
Posted: Tue Jan 07, 2014 9:34 am |
|
|
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.
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Jan 07, 2014 10:02 am |
|
|
Missing pull-up/-down resistors on RS485? |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Tue Jan 07, 2014 10:10 am |
|
|
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
|
|
Posted: Tue Jan 07, 2014 10:12 am |
|
|
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
|
|
Posted: Tue Jan 07, 2014 11:36 am |
|
|
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
|
|
Posted: Tue Jan 07, 2014 11:40 pm |
|
|
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
|
|
Posted: Wed Jan 08, 2014 12:25 am |
|
|
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
|
|
Posted: Thu Jan 09, 2014 9:50 am |
|
|
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!! |
|
|
|