View previous topic :: View next topic |
Author |
Message |
opvini
Joined: 27 Apr 2012 Posts: 50 Location: Brazil
|
Modbus with RS485 using MAX487 sending one char after all |
Posted: Thu Nov 08, 2012 8:06 am |
|
|
Hi...
I am making communication between PICs using Modbus (modbus.c). Its fine and works very well when I connect the PICs directly. But when I put the chip MAX487, I ever receive one character after all.
For example: I send "oi" I receive "oiï" but this last value is the same to the same transmitted data but this last value changes to different transmitted data.
I think that the MAX487 is sending one char to end of communication, but I'm not sure, then I come here to ask.
Thanks a LOT! |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Thu Nov 08, 2012 8:12 am |
|
|
The TX enable for the MAX487 in the sending PIC is disabling while the final charater is being sent. This happens when the enable is turned off once the last character has been put into the UART buffer instead of waiting for the character to finish being sent.
Someone here, Ttelmah possibly, or Temtronic, posted somce code here a while ago, and recently referred to it in another 485 related thread. Do a search on "485" and you should find it... which, of course you should already have done to see if the answer you need is already available. You did that, didn't you?
RF Developer. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19544
|
|
Posted: Thu Nov 08, 2012 8:20 am |
|
|
Almost certainly your problem is lack of bias on the RS485 bus.
Modbus, requires that the RS485 'A' line is pulled high, and the B line pulled low when the bus is not driven. This can be done by large value resistors, or combined with termination. The latter improves the ability of the bus too handle high frequencies, but reduces the number of nodes that can be used on the bus. Termination is optional, but biasing is required, unless you use a RS485 transceiver that is guaranteed to see an open bus as 'idle'.
If you don't have biasing, then you can see spurious start/data bits on the bus (hence your extra character, and it's random nature).
On RF_Developer's comment, 'yes' if you are using interrupt driven transmission.
However that loses the last byte, rather than gaining one. Hence my suspicion that biasing is the problem.
Best Wishes |
|
|
opvini
Joined: 27 Apr 2012 Posts: 50 Location: Brazil
|
|
Posted: Fri Nov 09, 2012 11:49 am |
|
|
Thanks a lot RF_Developer and Ttelmah!!
I actually searched the forum and have not found before, so I posted.
Well, I am using PROTEUS to simulate, and I KNOW IT HAS MANY BUGS, but it works fine with me to differents applications before I do on real board.
This is my scheme with a pull down resistor and a pull up resistor:
Any problems with the scheme? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Fri Nov 09, 2012 11:59 am |
|
|
1. normally you only have one termination resistor for the bus, so check with some RS-485 'bible' for the correct value. Can't read your schematic for values and of course don't know about cable lengths, capacitance, noise, etc....real world stuff.
2. as you are aware Proteus is NOT reliable, so don't think that just because it 'works' in a PC that your design/software will work in the real world. |
|
|
opvini
Joined: 27 Apr 2012 Posts: 50 Location: Brazil
|
|
Posted: Fri Nov 09, 2012 1:12 pm |
|
|
Sorry, about the image:
And I do not really trust the proteus, but it helps...
The question is: why without the MAX487 the comunication is OK and with MAX ever sending this last char. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Fri Nov 09, 2012 2:46 pm |
|
|
Simple answer is Proteus is NOT emulating the correct simulation of the PIC/CCS C/MAX487 combination.....
That's one of hundreds of reasons why no one can trust Proteus.
It is well known that it can't even follow simple DRCs..so why would you trust it to 'simulate' anything like a PIC?
To get 'real world' results you MUST hardwire PICs and test in the real world, anything less than that is asking for sleepless nights.
hth
jay |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Fri Nov 09, 2012 4:14 pm |
|
|
Apart from Proteus problems, the shown schematic is basically fine. It's supposed to work with PICs software
implementing correct transmit enable control.
The CCS MODBUS driver is an example of a software, that would work correctly with this hardware.
Personally, I would omit the 120 ohm termination for low speed and short range RS485 connections to save
power. The "bias" resistors are essential however. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19544
|
|
Posted: Sat Nov 10, 2012 2:23 am |
|
|
There is one glaring thing missing from the circuit (two things actually). Pull up resistors on the lines connecting to RX on the PIC's. 4K7 to 10KR to the supply rail on each of these lines. Otherwise when the receive buffer is turned 'off' during a transmission, you can receive spurious characters at the PIC if this line floats low. Again 'required'.
Best Wishes |
|
|
opvini
Joined: 27 Apr 2012 Posts: 50 Location: Brazil
|
|
Posted: Mon Nov 12, 2012 4:57 am |
|
|
Thanks a lot temtronic, FvM and Ttelmah!!!
I put the pull up resistors on the RX lines, thank you Ttelmah, and now I will test on real world, out the PROTEUS.
Thank everybody! |
|
|
|