Usart compile errors 18F4520


Closed Thread
Results 1 to 9 of 9
  1. #1
    Pedro Pinto's Avatar
    Pedro Pinto Guest

    Default Usart compile errors 18F4520

    Hello All

    I try to comunicate via Usart on PORTC.6 and PORTC.7 with Pic 18F4520
    and initiate with this:
    ' Initialize USART
    TRISC = %10111111 ' Set TX (PortC.6) to out, rest in
    SPBRG = 25 ' Set baud rate to 2400
    RCSTA = %10010000 ' Enable serial port and continuous receive
    TXSTA = %00100000 ' Enable transmit and asynchronous mode

    or with this:
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_BAUD 2400
    DEFINE HSER_SPBRG 25
    DEFINE HSER_CLROERR 1

    but, everytime i want compile the programm it show error messages like:
    Symbol not previously defined (RC2IF)
    Symbol not previously defined (PIR3)
    Symbol not previously defined (RCREG2)
    Symbol not previously defined (TX2IF)
    Symbol not previously defined (SPBRG2)
    Symbol not previously defined (TXREG2)
    Symbol not previously defined (TXSTA2)
    Symbol not previously defined (RCSTA2)

    I use PBP Pro 2.50 and Pic 18F4520
    with instruction like this:
    HSERIN2 800,final,[wait ("P"),dec2 function,dec3 pcb,dec3 dumy]

    Anyone idea what i make wrong?

    Thanks for help
    Regards
    Pedro

  2. #2
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Try HSERIN instead of HSERIN2.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  3. #3
    Pedro Pinto's Avatar
    Pedro Pinto Guest


    Did you find this post helpful? Yes | No

    Default

    Hello Bruce

    Thank You for help

    I have change all Hserin2 and Hserout2 instructions to Hserin and Hserout and the compiler donīt show more error messages
    Do you know why it don't accept the Hersxx2 option?

    Regards
    Pedro

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Pedro,

    How many hardware USARTs does your 18F4520 have?

    What does your PBP manual state HSERIN2 is for?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Pedro Pinto's Avatar
    Pedro Pinto Guest


    Did you find this post helpful? Yes | No

    Default

    Hello again

    With this initialisation i can receive well on the terminal program if i change on that the baudrate to 9600. What can be wrong, it must be 2400, or not?

    DEFINE OSC 16
    '
    ' Initialize USART
    TRISC = %10111111 ' Set TX (PortC.6) to out, rest in
    SPBRG = 25 ' Set baud rate to 2400
    RCSTA = %10010000 ' Enable serial port and continuous receive
    TXSTA = %00100000 ' Enable transmit and asynchronous mode
    '
    hserout ["SCCP",13,10]


    Regards
    Pedro

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


    Did you find this post helpful? Yes | No

    Default

    SPBRG = 25 is 2400 baud @4MHZ, not 16MHz.

    If you need 2400 baud @16Mhz you should try those settings
    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 103 ' 2400 Baud @ 16MHz, 0.17%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    @9600 bauds
    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_SPBRG 25  ' 9600 Baud @ 16MHz, 0.16%
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    etc etc etc.

    Try my PICMultiCalc for that.

    Download it from there
    http://www.picbasic.co.uk/forum/atta...7&d=1225550328
    Last edited by mister_e; - 6th May 2009 at 23:07.
    Steve

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

  7. #7
    Join Date
    Feb 2009
    Location
    Southern California
    Posts
    86


    Did you find this post helpful? Yes | No

    Default MR Es Pic Multi-calc

    using Mr E's Multi-calc's recommended settings

    9600 baud
    Code:
    RCSTA = $90   ' Enable serial port & continuous receive
    TXSTA = $24   ' Enable transmit, BRGH = 1
    SPBRG = 160   ' 9600 Baud @ -0.08%
    SPBRGH = 1
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    2400 baud
    Code:
    RCSTA = $90   ' Enable serial port & continuous receive
    TXSTA = $24   ' Enable transmit, BRGH = 1
    SPBRG = 130   ' 2400 Baud @ 0.0%
    SPBRGH = 6
    BAUDCON.3 = 1 ' Enable 16 bit baudrate generator
    The code you posted should have been sending data out at 9600 baud with SPBRG set to 25. Set SPBRG to 103 for 2400 baud. The error rate would be a little higher than the above code snippet (not that it would probably matter in the real world).

    Code:
    RCSTA = $90 ' Enable serial port & continuous receive
    TXSTA = $20 ' Enable transmit, BRGH = 0
    SPBRG = 103 ' 2400 Baud @ 0.17%
    Thanks to Mr E
    David

  8. #8
    Join Date
    Feb 2009
    Location
    Southern California
    Posts
    86


    Did you find this post helpful? Yes | No

    Wink

    I knew I left that post reply open too long...

  9. #9
    Join Date
    Feb 2009
    Location
    Southern California
    Posts
    86


    Did you find this post helpful? Yes | No

    Default version 1.3.1

    I didn't realize I was using an old version. I was still on 1.1.0

    Thanks for the update

    David

Similar Threads

  1. Unable to pass a variable to LCDOUT without getting compile errors
    By Ferroto Baggins in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th February 2010, 16:43
  2. USB PBPL Compile errors
    By Rob in forum USB
    Replies: 11
    Last Post: - 7th April 2008, 08:18
  3. USB Mpasm Compile errors
    By JBrannan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 21st December 2007, 18:13
  4. Replies: 2
    Last Post: - 10th July 2006, 01:05
  5. Compile errors within macro....
    By forgie in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 5th September 2005, 19: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