I ammm Looosssst (USART Help)


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2004
    Location
    nebraska
    Posts
    79

    Default I ammm Looosssst (USART Help)

    Hi Everyone,
    I need help please. What I am trying to figure out is how to use the Usart hardware on the pic 18F452. I need to comunicate between two or more Pics. I've used the serout and serin commands to do this but it is not efficent enough. The two pics will be doing whatever it is they need to do and from time to time they will need to send info back and forth.
    If I am not mistaking using the hardware usart they should be able to just send the info and whether the recieving pic is ready or not it will be written in the rx register. Also if I am not mistaking the pics should be able to interupt and retrieve this data once it is received.

    I Have no Idea where to start. I read Data sheets for the pic 18f452 and I skimmed threw threads and posts for hours and only got frustrated. Someone please point me in the right direction.

    By setting the correct registers one should not have to use the HSerin commands right or am I wrong. It appeared that by writing to the TX register that this would automaticly transmit my info as long as all the usart registers are config. properly.

    And while i Am at it can more than 2 pics be connected together using usart? I am sorry for asking questions that have already been asked, but answer are spread out all over the place and I have not figured out how to put the puzzle together.

    Thanks Shawn

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Assuming that you don't want to write an interrupt-driven routine -

    You can send data using HSEROUT and receive it with HSERIN.

    As far as the receive is concerned, probably the easiest way is to watch PIR1.5 If that bit is set, it means that a character was received. You can then use HSERIN to retrieve the byte.

    If you have lots of bytes to transfer between PICs, a good way is to use a line between the two as a "Clear To Send" line. You can easily do two-way communication that way. There are as many schemes as the number of users on this forum.
    Charles Linquist

  3. #3
    Join Date
    Dec 2004
    Location
    nebraska
    Posts
    79


    Did you find this post helpful? Yes | No

    Default

    I do want to use simple PBP Interups. Can't PIR1.5 be used as an interupt causing event.

  4. #4
    Join Date
    Dec 2004
    Location
    nebraska
    Posts
    79


    Did you find this post helpful? Yes | No

    Default

    This is the best I can come up with right now for a sample program. I am using 18f452 for the receiver and the transmiter. I want the receiver to use a PBP Interupt handler so that the microcontroller can do its thing and not half to wait idle for data from the transmiter.
    Transmiter code is :

    DEFINE LOADER_USED 1
    DEFINE OSC 4
    DEFINE HSER_RCSTA 90h ' enable serial port,
    ' enable continuous receive
    '
    define HSER_TXSTA 24h ' enable transmit,
    ' BRGH=1
    '
    define HSER_SPBRG 103 ' set baudrate to 2400
    DEFINE HSER_CLOERR 1 ' automatic clear overrun error

    TrisB.0 = 0

    Counter Var word
    DataIn Var Word
    DataOut Var Word

    Dataout = 10
    Counter = 0
    DataIn = 0



    Loop:
    PortB.0 = 1 'Led on
    hserout [DataOut] 'Serial Out PortC.6 Once every 5 seconds
    pause 3000
    PortB.0 = 0 'Led Off
    pause 2000
    GoTo Loop






    The Reciever code is:

    DEFINE LOADER_USED 1
    DEFINE OSC 4
    DEFINE HSER_RCSTA 90h ' enable serial port,
    ' enable continuous receive
    '
    define HSER_TXSTA 24h ' enable transmit,
    ' BRGH=1

    define HSER_SPBRG 103 ' set baudrate to 2400
    DEFINE HSER_CLOERR 1 ' automatic clear overrun error

    TrisB.0 = 0

    Counter Var word
    DataIn Var Word

    Counter = 0
    DataIn = 0

    on interrupt goto Reader

    'For Visual purposes to simulate doing something.
    'Flashing an LED on for half sec off for half sec.
    Main_Program:
    Counter = 0
    PortB.0 = 1
    While Counter < 500
    Counter = Counter + 1
    Pause 1
    wend
    Counter = 0
    PortB.0 = 0
    While Counter < 500
    Counter = Counter + 1
    Pause 1
    wend
    GoTo Main_program


    disable ' Disable interrupts
    Reader:
    rcsta.4 = 0 ' Clears Rx register overrun error,sets SREN off
    rcsta.4 = 1 ' Sets SREN on
    hserin [DataIn] 'PortC.7 serial In
    Serout PortB.1,6,[12,#DataIn] 'Display data on LCD
    pause 1000 'This pause should give a noticable
    'diference in Led flashing
    Serout PortB.1,6,[12] 'Clear LCD Display
    resume ' Leave interrupt routine
    enable

    Everything seems to be working except the reciever module never goes into the interupt routine. Also the Transmiter TX line seems to be always high. I came up with this test code from the PBP manual and many post here.
    Last edited by shawn; - 14th May 2006 at 03:59.

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


    Did you find this post helpful? Yes | No

    Default

    Steve

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

  6. #6
    Join Date
    Dec 2004
    Location
    nebraska
    Posts
    79


    Did you find this post helpful? Yes | No

    Default

    Thanks Steve
    That worked, I will probably have more questions but that defenitly gave me something to work with.

Similar Threads

  1. byte Tx w/ USART 16f876a problem
    By GargamelDigi in forum mel PIC BASIC
    Replies: 2
    Last Post: - 15th July 2008, 05:50
  2. Usart Questions
    By shawn in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2008, 01:17
  3. problem with USART
    By leemin in forum Serial
    Replies: 4
    Last Post: - 11th December 2006, 17:56
  4. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07
  5. Replies: 5
    Last Post: - 1st December 2004, 12:49

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