Why is this so hard? HSEROUT problems.


Closed Thread
Results 1 to 4 of 4
  1. #1
    groston's Avatar
    groston Guest

    Unhappy Why is this so hard? HSEROUT problems.

    I have been working with PIC and PBP for several weeks now. Thus far, it has been a continual exercise in frustration. (FYI - I have been developing real-time control systems for 20 years, i.e., I am not a neophyte.)

    Enough griping. (Well, the PBP documentation sucks - OK, griping done.)

    My application, built using a PIC 16F88 with PBP V2.47, is not working. So, I figured I'd use the debugging capability in microCode Studio (V 2.3.0.0) to try to figure things out. (I have the meLabs U2 USB programmer.) Couldn't get it to work. So, I built a simple circuit to test serial communications. This also doesn't work.

    I have attached a zip file with some further information:
    1: commCircuit.gif: this shows the as-built schematic. Much of this was copied from the schematic for the meLabs X18 board.
    2: serTst.pbp: he exciting source code, all 41 lines of it
    3: config.jpg: screen shot of the configuration option for the meLabs Programmer (V4.20)
    4: output.txt: data acquired using the built-in serial communication tool

    What I have observed:
    1: The LED should flash with a period of one second on, one second off. It does not. It turns one and off, typically more than once per second, with the time period seemingly random.
    2: The serial message received are garbage. (see output.txt)
    3: Changing the baud rate from 9600 to 300 had no impact.

    I think the hardware is configured properly, but this just isn't working. (In fact, at one point, I had forgotten to hook pin 15 of the MAX232 to ground, and with this pin floating and with the HSERIN line commented out, the system performed mostly as expected... weird.)

    I can really use your help. I am already behind schedule and due to familial obligations, am likely to fall even further behind without help.

    Thank you!
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Hi Groston,

    Let me post your code here first.

    Code:
    '****************************************************************
      OSCCON = $60 ' set the internal clock to 4 MHz
      define OSC 4 ' set osc to 4 MHz
     
      TRISB.0 = 0           ' Set RB0 to output
    
      ' Initialize USART
      define HSER_TXSTA 24h ' Enable transmit and asynchronous mode
      define HSER_RCSTA 90h ' Enable serial port and continuous receive
      define HSER_BAUD 9600 ' Set baud rate to 9600
    
      recv var byte
      cntr var word
      recv = 0 
      cntr = 0
    
    ADC_loop:
      if recv = 0 then
        hserout ["message ", dec cntr, 13]
      else
        hserout ["Other", 13]
      endif
    
      if cntr = 255 then
        cntr = 0
      else
        cntr = cntr + 1
      endif
    
      PORTB.0 = 0  
      pause 1000      ' 1 sec delay
      
      PORTB.0 = 1
      pause 1000      ' 1 sec delay
      
      hserin 1, missed, [recv]
      
      goto ADC_loop
    
    missed:
      recv = 0
      goto ADC_loop

    What was your idea in the red part?

    Could you give details as to understand what you wanted to do there? Currently, as it is now, it can not work.


    --------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default Hang in there!

    Hi Groston,
    The PIC is obviously sending the data out. You are running with the internal oscillator and it may be that it's not precise enough for the baud rate generator to produce the correct timing. Can you try it with a external crystal instead. (I think it should've worked when you tested at 300baud though, but you'll never know).

    Try to get the PIC to send data correctly first. (I know that's what your doing) but perhaps something even more simple, like:
    Code:
    i var byte
    Loop:
      i = i + 1
      HSEROUT [#i, 13]
      Toggle PortB.0
      Pause 1000
      Goto Loop
    Let us know.

    /Henrik Olsson.

  4. #4
    groston's Avatar
    groston Guest


    Did you find this post helpful? Yes | No

    Default

    Henrik,

    I will try your suggested code a bit later today.

    As for the intent of the section in red:
    I was simply looking to see if the program would recognize incoming serial data. By using the built-in serial communications window, my plan was to send a character every so often to see if the alternate message was outputted.

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. Problems with HSERIN HSEROUT
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 20th September 2005, 17:24
  5. HSEROUT Problems
    By SergioRM in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th April 2005, 23:17

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