PDA

View Full Version : RS485/PIC18F4520-Interrupt not firing for all recieved bytes



DavidKnott
- 8th July 2009, 12:17
Hello to all forum members, hopefully somebody can point me in the right direction.

I have setup a simple PIC18F4520 demo board, using a 10Mhz crystal. My Rx + Tx pins are connected directly to a Maxim 3080 rs485 transciever. PIC port D0 is connected to my { driver enable, (!reciever enable) } on the transciever. I am using a very short run of rj45 cable with no biasing or terminating resistors. I am using a baud rate of 115200.

A PC is acting as bus master and sending simple ascii strings to the PIC using realterm.

Sending characters from the PIC to the PC works fine, no characters are lost.

Only the first 3 characters are triggering the rx interrupt when transmitting from the PC to the PIC.

For example, I have set a breakpoint on the interrupt handler. When I send 'abcde' from the PC terminal, the breakpoint is only triggered for the 3 chars, a, b and c. The additional chars seem to be ignored.

I could work around this, however I would like to understand what is happening.

Thanks !

David

Jerson
- 8th July 2009, 13:25
First off, without seeing code, it's very hard to comment accurately. Off the cuff, my rule of thumb is to not run the serial port at 115200 unless you are absolutely sure what you're doing. There are lots of things that can trip your code at this speed. Why not try a reasonable baud rate of 4800 or 9600 to check if your baud rate is the problem.

Jumper
- 8th July 2009, 17:06
Are you sure you have the rx enable on long enough to receive all characters and that you dont switch over to tx mode too fast before all stuff has arrived?

DavidKnott
- 9th July 2009, 09:14
Thanks for your responses. I reduced the baud rate and removed checking for overruns + framing errors. This seems to have solved my problem. Still not entirely sure why it works now, but its a start !

dhouston
- 9th July 2009, 10:44
At 115200 you definitely need termination resistors at the ends of the RS485 bus. For a simple way to automatically control the TE/RE turn-around see FIG 4, p23 of...http://www.embeddedsys.com/subpages/resources/images/documents/microsys_art_RS485.pdf

DavidKnott
- 9th July 2009, 11:02
@dhouston

Thanks, I might give that a go, now that I know that the circuit is working.
I reduced the baud rate to 4800 as suggested by another member but I am still not using termination. I did read somewhere that if you are using short wiring line termination and biasing can cause more problems than it solves, however this may be only relevant for higher baud rates.

dhouston
- 9th July 2009, 12:11
Termination is not needed at low speeds but is a must at high speeds.

Here is one of the best RS485 tutorials I've seen.http://www.bb-elec.com/tech_articles/rs422_485_app_note/table_of_contents.asp

And, anything by Jan Axelson on the topic is worth reading. She writes with great clarity making technical topics easy to grasp.