Serial Mishaps


Results 1 to 3 of 3

Thread: Serial Mishaps

Threaded View

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

    Default Serial Mishaps

    Hello,
    I am having problems receiving serial information.
    What I want to do is have my pic18f4585 interrupt on a rx interrupt and load the data into an array. I am having major issues. No matter what I do I only receive 2 bytes worth of info. I am using MCS serial communicator to test and an lcd.

    When I try this code and send abcdefgh with MCS serial communicator, I get back ab followed by a bunch of garbage
    Code:
    ***********************************************************************************
    Define OSC 20   
    
    TXSTA = $24
    'TXSTA.0 =                 Can be address/data bit or a parity bit.
    'TXSTA.1 =  0              '0 = TSR full
    'TXSTA.2 =  1              '1 = High speed
    'TXSTA.3 =                 Unimplemented: Read as ‘0’
    'TXSTA.4 =  0              '0 = Asynchronous mode
    'TXSTA.5 =  1              '1 = Transmit enabled.
    'TXSTA.6 =  0              '0 = Selects 8-bit transmission
    'TXSTA.7 =                 Don’t care.
    
    RCSTA = $90
    'RCSTA.0  =                Can be address/data bit or a parity bit.
    'RCSTA.1  = 0              '0 = No overrun error
    'RCSTA.2  = 0              '0 = No framing error
    'RCSTA.3  = 0              '0 = Disables address detection.
    'RCSTA.4  = 1              '1 = Enables continuous receive.
    'RCSTA.5  = 0              '0 = Disables single receive.
    'RCSTA.6  = 0              '0 = Selects 8-bit reception.
    'RCSTA.7  = 1              '1 = Serial port enabled.
    
    SPBRG    = 10             '64 = 19200 Baud Asynchronous mode, High Speed.
    
    INTCON.7 = 1              '1 = Enables all unmasked interrupts
    INTCON.6 = 1              '1 = Enables all unmasked peripheral interrupts.
    INTCON2.5 = 0             'INT1 edge select 0 = Falling Edge.
    INTCON2.7 = 1             'Disable portb pullups.
    INTCON3.3 = 1             'Enable INT1 interrupt.
    RCON.7   = 0              '0 = Disable priority levels on interrupts.
    PIE1.5   = 1              '1 = Enables the USART receive interrupt.
    PIE1.4   = 0              '0 = Disables the USART transmit interrupt.
    
    LCD         Var PortC.3  'LCD Output alias.
    RCIF        var PIR1.5   'RCIF: USART Receive Interrupt Flag bit. 
    TXIF        Var PIR1.4   'TXIF: USART Transmit Interrupt Flag bit.
    
    Index      var Byte
    SerialData Var Byte[40]
    
    On Interrupt Goto INTERUPTS 'Define interrupt handler
    
    Pause 10                'Allows Stuff to get ready
    
    pause 5000
    
    Main:
    
    Goto Main
    
    Disable
    INTERUPTS:
    
    Serout2 LCD,16468,[16,105] 
    Index = 0
    
    while RCif               
            SerialData[index]=RCREG         ' by reading it and store result in a
            Index = Index + 1
    wend
    Index = 0
    
    While Index < 8
        HSerout [SerialData[Index]]
        Index = Index + 1
        Serout2 LCD,16468,[SerialData[index]]
    Wend    
    
    resume
    '*******************************************************************************
    
    enable
    end
    ***********************************************************************************
    Where am I going wrong I think I am close. This code almost matches some examples I have found on the forum. Eventualy I am going to worp this program into modbus rtu.
    Help me Please.
    Last edited by ScaleRobotics; - 4th July 2010 at 17:58. Reason: added code tags

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