RS485 serial communication


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2007
    Posts
    3

    Default RS485 serial communication

    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 ?

  2. #2
    Join Date
    Aug 2005
    Posts
    95

    Default

    Have you terminated both ends of the cable with a 120 ohm resistor.

    Sphere...

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    if you want to make sure, you may decide to use the wait modifier.

    On the send side, you use something like...
    Code:
    HSEROUT ["UUUU-OK",ByteA, ByteB, ByteC, ByteD]
    on the receiver side...
    Code:
    HSERIN [WAIT("OK"),ByteA, ByteB, ByteC, ByteD]
    For your first test, just remove the transceiver, if it's working, add them.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Feb 2007
    Posts
    3

    Smile

    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

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521

    Default

    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.

  6. #6
    Join Date
    Feb 2007
    Posts
    3

    Smile resolved

    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

Similar Threads

  1. Wireless serial communication question
    By Ahmadabuomar in forum Serial
    Replies: 3
    Last Post: - 21st December 2009, 03:49
  2. PIC to PIC "wired" serial one-way communication - SERIN2/SEROUT2
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th April 2008, 20:02
  3. Bootloader,MCSP and Serial communication
    By surfer0815 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd March 2006, 10:52
  4. Serial Communication using 12F629
    By charudatt in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th March 2005, 04:24
  5. Replies: 8
    Last Post: - 11th November 2004, 20:08

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts