Serial communication between PIC and Atmega controileer trough RS485


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Nov 2011
    Posts
    12

    Default Serial communication between PIC and Atmega controileer trough RS485

    Hello,
    I allready post on the melabs forum. But here is another very visit forum, perhaps anyone can help me

    Hours try to comunicate to a 7segment display without sucess

    I have a 18f4520 on there i conect on Porte.0 and Porte.2 TX and RX pins of a RS485 driver to send data to a 7segment display that have also a RS485 driver.

    The direction pin is already output and also high for transmitting
    dir_rs485 var PORTE.1 'RS485 Mode
    high dir_rs485 'transmitting mode

    The 7segment display have a Atmega88P controller. This display works on a network of manys slaves very good, all with Atmega controllers at baudrate 38400.
    Now i want to communicate with this display trough a pic 18f4520 on baud 2400. I tried everything like:

    disp_pos var PORTE.0 'Tx to a RS485 driver

    serout2 disp_pos,16780,5,[hex2 master,hex2 destino,hex2 posicao,13,10]
    serout2 disp_pos,16780,5,[hex2 master,hex2 destino,hex2 posicao,13]
    serout2 disp_pos,16780,5,[hex2 master,hex2 destino,hex2 posicao,10]
    serout2 disp_pos,16780,5,[hex2 master,hex2 destino,hex2 posicao]
    serout2 disp_pos,16780,5,[#master,#destino,#posicao,13,10]
    serout2 disp_pos,16780,5,[#master,#destino,#posicao,13]
    serout2 disp_pos,16780,5,[#master,#destino,#posicao,10]
    serout2 disp_pos,16780,5,[#master,#destino,#posicao]

    All the same with serout2 disp_pos,396,5,
    serout2 disp_pos,33164,5,
    serout2 disp_pos,49548,5,
    Like i said the display works fine on the Atmega as slave on the Atmegas network

    Have the same baud of 2400 on the display

    Anyone idea what i make wrong on the pic code?
    Compiled with PBP247

    Thanks in advance
    visitac

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Serial communication between PIC and Atmega controileer trough RS485

    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Serial communication between PIC and Atmega controileer trough RS485

    It is not too clear, from your post, the question of the baud rate. If your RS485 existing network, works at 38400 bauds then you must Tx out your commands at the same speed. This means you cannot use 2400 bauds.

    If I have corectly understood the baud rate question, then you will never reach that speed with serout2. You will need to use the hserout comand which use the Hardware USART.

    Cheers

    Al.
    All progress began with an idea

  4. #4
    Join Date
    Nov 2011
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Serial communication between PIC and Atmega controileer trough RS485

    Hello aratti,

    On both boards have the same baud of 2400. I have write about the 38400 baud to show you that the 7segment display board works on other network with baud of 38400. For this project i have changed the baud to 2400 like the baud on the Pic controller.

    Best regards
    visitac

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: Serial communication between PIC and Atmega controileer trough RS485

    Did you check the ADC ?
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Nov 2011
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Serial communication between PIC and Atmega controileer trough RS485

    Hello mackrackit,

    I write on start of the programm ADCON1 = 7
    You mean that?

    Best regards
    visitac

  7. #7
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Serial communication between PIC and Atmega controileer trough RS485

    ..OK, all your network devices works at 2400 baud. First question: did you put the two 620 ohms resistors on the head and tail of your network? Remember that you need to connect a pullup on channel A and a pulldown on channel B at the extreme of your network.

    Next remove the "pace" value form your code. Between placing high portE.0 and the serout comand, place a 2 - 5 milliseconds delay using "PAUSE 5"

    Cheers

    Al.
    All progress began with an idea

  8. #8
    Join Date
    Nov 2011
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Serial communication between PIC and Atmega controileer trough RS485

    Hello aratti,

    Yes i have the pulldown and the pullup resistors connect, not solve

    with this i receive on the display the data on the atmega88 controller that works as slave

    _start:

    If Ischarwaiting() <> 0 Then 'test if char arrive
    Inputbin Serialchar 'get it
    If Serialchar <> 254 Then Goto _start 'the first value must be 254
    Inputbin , T_destino , Crypt 'get the rest two values
    Clear Serialin
    End If


    the works as master, and send this binary data

    i try to send it as decimal as too hex
    serout2 disp_pos,396,[dec master,dec destino,dec posicao]
    and also
    pause 1000
    serout2 disp_pos,396,[hex2 master,hex2 destino,hex2 posicao]

    unfortunatly without sucess

    I have no more idea what can be wrong

    Best regards
    visitac

  9. #9


    Did you find this post helpful? Yes | No

    Default Re: Serial communication between PIC and Atmega controileer trough RS485

    Just a thought, if you have accidently crossed the rs485 wires, then the signal will be inverted at the receiving end, so your serial data would be inverted.

  10. #10
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: Serial communication between PIC and Atmega controileer trough RS485

    With fragment of code and no schematic, I personally think you cannot get much more help. Please post the whole code you are using, along with some reference to the data sheet of the slaves you have installed in your network. Naturaly complete the info with a schematic on the setup.
    With a more complete picture you will have a better chance to get the corrected advice.

    Cheers

    Al.
    All progress began with an idea

  11. #11
    Join Date
    Nov 2011
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Serial communication between PIC and Atmega controileer trough RS485

    Hello aratti,

    The network is only one master, the pic controller, on there i use serout2 and a 7segment display as slave, that use a Atmega88P. Both with baud 2400
    The display works fine on other project as slave too on baud 38400, all with Atmega controllers. The display is not a problem, the protocol is the same,
    only on this project with the pic i have change the baud to 2400. With software uart it not possible to work on baud 38400. Why i have change the baud on the
    display to 2400.

    I can draw a schematic tomorrow, but like i said the display is working on the other project. On the board with the pic i have connect PORTE.0 to pin 4 and PORTE.2 to pin 1
    of the max487. The pin 2 and 3 of the max487 connect together to PORTE.1. On startup make the PORTE.1 as output and high for transmit mode. A is connected to A and B to B of the max487 on the display.

    Best regards
    visitac

  12. #12
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Serial communication between PIC and Atmega controileer trough RS485

    Pullup and Pulldown resistors are mearly safeguards for disconnect conditions. I do not hear of any bus termination resistors in place? There should be a termination resistor on each END of the bus between bus+ and bus-. I would a quick verification of the IDLE state of the bus by allowing it to go IDLE (with no traffic) and look at the RX output pin of the MAX487 to make sure it is in the correct IDLE state. This will infact tell you if the bus connections are reversed. SERIN statements do not act very well when they are in the reversed states. The program tends to hang. I would also place a pullup resistor on the RX pin of the PIC to ensure it's state during the time the TX enable of the MAX487 as the RX output line will go tristate.
    Last edited by Dave; - 5th October 2012 at 11:44.
    Dave Purola,
    N8NTA
    EN82fn

  13. #13
    Join Date
    Nov 2011
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Serial communication between PIC and Atmega controileer trough RS485

    Hello,
    Thanks to all that try to help. For Feedback purpose,

    Now it works, but not with Serout2 but trough debug,

    ' Set Debug pin port
    DEFINE DEBUG_REG PORTE
    ' Set Debug pin bit
    DEFINE DEBUG_BIT 0
    ' Set Debug baud rate
    DEFINE DEBUG_BAUD 2400
    ' Set Debug mode: 0 = true
    DEFINE DEBUG_MODE 0

    debug master,destino,posicao 'this works


    disp_pos var PORTE.0 'TX
    dir_rs485 var PORTE.1 'RS485 tx Mode
    high dir_rs485 'set to transmit mode
    serie_in var PORTE.2 'RX 'not need in this project

    serout2 disp_pos,396,[master,destino,posicao] 'dont't work

    Not idea why serout2 not work.

    Best regards
    visitac

Similar Threads

  1. USB / RS485 communication
    By Pedro Pinto in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 7th May 2009, 19:36
  2. rs485 communication
    By dreamman in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th June 2007, 21:47
  3. RS485 serial communication
    By mipie in forum Serial
    Replies: 5
    Last Post: - 10th February 2007, 13:15
  4. PIC to PIC RS485 with users the communication
    By x0914667 in forum Serial
    Replies: 2
    Last Post: - 21st July 2005, 00:20
  5. put an id adress on one pic for rs485 communication
    By ON4XAV in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 12th June 2005, 12:54

Members who have read this thread : 0

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