HSEROUT problem at 20MHz


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Location
    Isle of Man
    Posts
    32

    Cool HSEROUT problem at 20MHz

    I am using a PIC18F452, with a MAX232 and the HSEROUT function to communicate with my PC over a 3m long serial cable. My code is based on the famous post on this forum (many thanks!):

    DEFINE OSC 4

    TRISC = %10000000 'PORTC.7 is RX input PORTC.6 is TX output. Using internal USART and MAX232 to interface to PC

    DEFINE HSER_RCSTA 90h 'Enable serial port. Enable continuous receive

    define HSER_TXSTA 24h 'Enable transmit. BRGH=1

    define HSER_SPBRG 12 '103 for baudrate of 2400 @ 4MHz (25 for 9600 @ 4MHz; 12 for 19200 @ 4MHz)
    DEFINE HSER_CLOERR 1 'Automatic clear overrun error

    'Alias definitions
    RCIF VAR PIR1.5 'Receive interrupt flag (1=full , 0=empty)
    TXIF VAR PIR1.4 'Transmit interrupt flag (1=empty, 0=full)

    SerialData var byte 'Variable definition

    pause 100 'Start-up delay
    Main:
    if RCIF then 'Incoming data?
    hserin [Serialdata] 'Take it
    hserout [serialdata] 'Send it
    endif
    goto main


    This provides perfect 2-way comunications at 4MHz with any of the following settings:

    'TXTA 24h with SPBRG 103 (gives 2400 baud)
    'TXTA 24h with SPBRG 25 (gives 9600 baud)
    'TXTA 24h with SPBRG 12 (gives 19200 baud)

    .... but when I change the clock to 20MHz and alter the SPBRG value according to the datasheet, there is no comms at all. For example, although 19200 baud requires SPBRG to be 64, this produces nothing.

    I'm desperate! Any ideas folks?
    Last edited by manxman; - 22nd May 2006 at 12:40.

  2. #2
    Join Date
    Oct 2004
    Location
    Hangover, Germany
    Posts
    289


    Did you find this post helpful? Yes | No

    Default

    You changed the "define OSC 4" to "define OSC 20" too ?
    PBP 2.50C, MCS+ 3.0.0.5, MPLAB 8, MPASM 5.14, ASIX Presto, PoScope, mE mikroBasic V7.2, PICKIT2

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


    Did you find this post helpful? Yes | No

    Default

    AND you set the HS config fuse in your code or before programming in your device programmer software?
    Steve

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

  4. #4
    Join Date
    Feb 2006
    Location
    Isle of Man
    Posts
    32


    Did you find this post helpful? Yes | No

    Default HSEROUT problem at 20MHz

    Hellow guys,

    Yes, I changed the programmer clock speed config. setting to HS and the DEFINE OSC 4 to DEFINE OSC 20

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


    Did you find this post helpful? Yes | No

    Default

    Sometimes, the breadboard could cause you some bugs like that. But before doing some assumption, is a simple Blink program work? Some crystal also need a resistor in parallel to work properly.. something 'round 1Meg

    If not, remove the capacitor around your Crystal, ALSO be sure your supply line is clean, ... plah plah, capacitor close to PIC and the usual.

    DOH! i already saw that code here ... i guess it's one of mine.. there's a little error in the DEFINE HSER_CLOERR... MUST BE DEFINE HSER_CLROERR

    Do a simple loop with HSEROUT and post your results.
    Last edited by mister_e; - 22nd May 2006 at 16:20.
    Steve

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

  6. #6
    Join Date
    Feb 2006
    Location
    Isle of Man
    Posts
    32


    Did you find this post helpful? Yes | No

    Cool HSEROUT at 20MHz

    Thanks for your suggestions. I corrected the CLROERR microbug, with no effect and then inserted an [LED ON : PAUSE : LED OFF] bit between the byte receive and byte echo lines in the code. This proved that the micro and code were running, with the LED blinking for each byte received. However, after a random number of bytes received (typically 6), the program stops with the LED on.

    Tidying up the breadboad wiring and moving the power input lines connection to the board greadtly improves things. Most of the bytes are now echoed correctly, with a few random errors. This all suggests that it is a board layout problem giving noise on the power lines that latches up the micro. The funny thing is that I used 9600 baud with 20MHz, no absolutely problem, when using SEROUT and NO MAX232. It seems that the MAX232 is producing these glitches.

    I hope the problem will be fully solved when I go to a PCB. Thanks for the suggestions.

Similar Threads

  1. I2C Slave with a PIC
    By ralfmayr in forum mel PIC BASIC Pro
    Replies: 129
    Last Post: - 21st August 2016, 17:44
  2. HSEROUT and Commas, What? Help Me Understand
    By altech6983 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 20th July 2009, 19:12
  3. Is HSEROUT corrupting bit 7 ?????
    By Robert Wells in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd October 2008, 16:26
  4. HSEROUT Problem
    By Keith in forum General
    Replies: 2
    Last Post: - 25th June 2005, 15:09
  5. Advantages of HSerout over Serout2 and a problem
    By rpstroj in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th August 2004, 22:19

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