PDA

View Full Version : RS485 serial communication



mipie
- 5th February 2007, 17:09
Hello,

I'm connecting a PIC 16F876 and a 16F88 through SP485CS transceivers. First, I was getting errors and I read somewhere in the forum that quartz were necessary on both PICs. I added a quartz on the 16F88 and the data transmission was OK in my lab.
I have installed the system in a large building and the circuits are about 70 meters distant. I'm having the same old errors with datas mixed.
I send 10 bytes making 5 words using:
HSerout [b1,b2,...b10]
and when i display them, the order is not respected, w2 can be first or w3.

Both PICs are running at 4 MHz. The cable between the RS485 is a data transmission cable shielded, I have tried to connect the shield to the main ground (on one side only) or not (no change).

The defines for the RS485 are:
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 103

Is there a way to slow down the system and be sure that the receiver will know which data is the first ?

Sphere
- 5th February 2007, 19:02
Have you terminated both ends of the cable with a 120 ohm resistor.

Sphere...

mister_e
- 5th February 2007, 19:08
if you want to make sure, you may decide to use the wait modifier.

On the send side, you use something like...


HSEROUT ["UUUU-OK",ByteA, ByteB, ByteC, ByteD]


on the receiver side...


HSERIN [WAIT("OK"),ByteA, ByteB, ByteC, ByteD]


For your first test, just remove the transceiver, if it's working, add them.

mipie
- 5th February 2007, 19:56
Thank you for your messages.

There are 120 ohms resistors on both ends.

I'll try tomorrow the simple advice of adding a first known byte- it should work since I'm sending info in to one direction only.

Best regards

HenrikOlsson
- 6th February 2007, 07:25
Hi,
Remember also that if you're switching the tranciever in and out of transmit mode with the PIC you will need a short pause after the HSEROUT statement so that the USART will have time to spit out the bits before you switch off the tranmitter. The length of the pause depends on the baudrate.

The HSEROUT command finishes when it puts the last byte in the USART transmit register so if you don't pause there that byte will not be sent correctly.

HTH
/Henrik Olsson.

mipie
- 10th February 2007, 14:15
Thank you Steve - it works now and info are not anymore mixed.
Doing the modifications, I found two interesting errors:

1. If you dont insert a space between WAIT and the parenthesis, there is no errors at compilation but it does not work.

2. My system sends information between three spots - I modified between spot 2 and 3, it worked and then when I dit it between 1 and 2, I wrote HSERIN [WAIT ($),b1,b2,...] instead of HSERIN [WAIT ("$"),b1,b2,...] and while compiling, I got the usual windows error message saying "XP is closing the PbP246 compiler, should we send a message to big brother of R ?"
This is the first time I get such an error during compilation - it took me a long time to find the error - I thought first that my computer had caught a new virus or something.

In general , I must thank all the participants of this forum and especially a few of them (big donators of their time and experience). I 'm an old engineer and without your help, it would have been very difficult for me to start using PICs and to find the huge quantity of information in all your messages.
When I start a new design, I have ideas how to solve the problem but my first action is consulting your pages (usually, one of you has already had to solve the same problem and I will find here other points of view, other ideas and this is very encouraging).
It was the first time, I asked a question and a few hours later, Steve solved the problem and I discovered that I had not read with enough attention the manual.
I hope I will be able to bring also some of my small experience to you if I know one answer to a question.

Best regards to all the users,

Michel