USART problems


Results 1 to 40 of 48

Thread: USART problems

Threaded View

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


    Did you find this post helpful? Yes | No

    Default

    If you use HSERIN & HSEROUT, then use the PBP USART defines.

    Otherwise, when you compile, the PBP USART library routines attempt to set USART registers & baud rate automatically based on the defined OSC value.

    If the defined OSC speed doesn't jive with 2400 baud (which is the PBP default data rate if you do not use the USART defines), then it returns the error "Argument out of range".

    That's why when you change DEFINE OSC 40 to DEFINE OSC 20 it works. 40MHz didn't work out during PBP's attempt to compute reg values for 2400 bps by default.

    Look in your PBPPIC18.LIB file just under ;* Default hardware serial port values.

    You'll see the logical progression taken through the library as it tries to setup default USART parameters.

    ifndef HSER_BITS
    HSER_BITS = 8 ; Default to 8 bits
    endif

    If NOT defined HSER_BITS, then by default let's use 8-bit.

    ifndef HSER_RCSTA ; Receive register data
    if (HSER_BITS != 9)
    HSER_RCSTA EQU 90h ; Receiver enabled
    else
    HSER_RCSTA EQU 0d0h ; Receiver enabled for 9 bits
    endif

    If NOT defined HSER_RCSTA and if HSER_BITS is NOT = 9, then set HSER_RCSTA to 90h. Or else set it to 0d0h for 9-bit.

    Follow this down to where OSC, HSER_TXSTA, and HSER_BAUD are used to "automatically" compute the value for HSER_SPBRG and you'll see why the argument out of range error pops up. The numbers don't work out for 2400bps at 40MHz.

    In short;

    If you're not using HSERIN or HSEROUT, and just want to do everything manually by reading RCREG, handling over-runs, clearing RCIF, etc, then setup the USART registers manually as mentioned previously.

    If you "are" using HSERIN & HSEROUT anywhere in your program, then you need to use the PBP USART defines - or select an oscillator speed that works with the default 2400bps.
    Last edited by Bruce; - 27th January 2005 at 21:45.
    Regards,

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

Similar Threads

  1. My USART problems..
    By Glenn in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 31st July 2009, 01:00
  2. problem with USART
    By leemin in forum Serial
    Replies: 4
    Last Post: - 11th December 2006, 17:56
  3. USART TXREG Problems
    By BigH in forum Serial
    Replies: 2
    Last Post: - 11th January 2006, 00:30
  4. Replies: 5
    Last Post: - 1st December 2004, 12:49
  5. Synchronous USART problems... HELP!!!
    By moni in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 14th November 2003, 19:00

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