Hserin Syntax


Closed Thread
Results 1 to 7 of 7

Thread: Hserin Syntax

  1. #1
    Join Date
    Apr 2012
    Location
    Ptolemaida
    Posts
    50

    Post Hserin Syntax

    Hello there Im working with a project and using the Hserin command is my final Step to finish it ( i need PC-MCU communication on background ).
    Im using PIC18F26K22 it's kind new controller but so easy to work with and so good.
    I have made C7 input and C6 output from TRISC register (C6/C7 = TX1/RX1)

    Communication Configs on laptop are

    Baud = 9600
    Parity = No Parity
    ByteSize = 8
    StopBits = 1

    Code:
    DEFINE OSC 32
    DEFINE HSER_BAUD 9600 'Hser baud rate 
    DEFINE HSER_CLROERR 1 'Hser clear overflow automatically 
    DEFINE HSER_SPBRG 25 'Hser spbrg init 
    DEFINE HSER_RCSTA 90h 'Hser receive status init 
    DEFINE HSER_BITS 9 'Hser Use 9th bit for parity
    
    Main:
      hserin [str rec\10]
      for i=0 to 10
        hserout [rec[i],13,10]
      next i
      pause 1000
      
    goto main
    This is the part of the code that i use Hserin and Hserout (to see if what's pic is taking are correct )

    Can you help me ?? Do i have wrong syntax ?? or Wrong Defines ?? I just got tired today for searching ways to make EUSART work

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


    Did you find this post helpful? Yes | No

    Default Re: Hserin Syntax

    Hi,
    One thing is that you claim to have the laptop set to no parity but the code is setup for 9 bits. I'd remove the DEFINE HSER_BITS 9.
    Also, you're receiving a string of 10 bytes but you're sending 11 bytes (+13,10). Shouldn't prevent it from running though.
    Then I'd do a simple HSEROUT["Program Start",10,13] before entering the Main loop - just to see if the USART is alive and the connection is OK.

    /Henrik.

  3. #3
    Join Date
    Apr 2012
    Location
    Ptolemaida
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: Hserin Syntax

    Thank you a lot Henrik for the advises ill work on it when i get back from college.
    Last edited by xapmanis; - 9th April 2013 at 07:46.

  4. #4
    Join Date
    Apr 2012
    Location
    Ptolemaida
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: Hserin Syntax

    Hello Henrik, I got back home and did run some tests. I found what i did wrong !! I did put wrong defines.
    The only defines a simple HSEROUT/HSERIN needs are:

    DEFINE HSER_RCSTA 90h 'Hser receive status init
    DEFINE HSER_TXSTA 20h 'Hser transmit status init
    DEFINE HSER_BAUD 9600 'Hser baud rate
    DEFINE HSER_CLROERR 1 'Hser clear overflow automatically

    The thing that put me through trouble was that
    DEFINE HSER_BAUD 9600 and DEFINE HSER_SPBRG 25 does the same thing, they set the BaudRate and u can't use them both (what i did !!) :P

    Mistakes on pics can sometimes drive me crazy !! Thank you for your reply

    Regards, Kostas

  5. #5
    Join Date
    Apr 2012
    Location
    Ptolemaida
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: Hserin Syntax

    Hello Henrik, I got back home and did run some tests. I found what i did wrong !! I did put wrong defines.
    The only defines a simple HSEROUT/HSERIN needs are:

    DEFINE HSER_RCSTA 90h 'Hser receive status init
    DEFINE HSER_TXSTA 20h 'Hser transmit status init
    DEFINE HSER_BAUD 9600 'Hser baud rate
    DEFINE HSER_CLROERR 1 'Hser clear overflow automatically

    The thing that put me through trouble was that
    DEFINE HSER_BAUD 9600 and DEFINE HSER_SPBRG 25 does the same thing, they set the BaudRate and u can't use them both (what i did !!) :P

    Mistakes on pics can sometimes drive me crazy !! Thank you for your reply

    Regards, Kostas

  6. #6
    Join Date
    Oct 2011
    Posts
    54


    Did you find this post helpful? Yes | No

    Default Re: Hserin Syntax

    Hi
    When using the PIC USART the Tx pin should be set to INPUT, not output as you would expect.
    See PIC 18F2x/4xK22 datasheet page 270 section 16.1.1.7
    Phil

  7. #7
    Join Date
    Apr 2012
    Location
    Ptolemaida
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: Hserin Syntax

    Hey phil, i just read page 270. It's true what you said but it seems to work both ways. I think Hserout/Hserin sets TRIS register automatically.
    Regards Kostas.

Similar Threads

  1. Syntax error
    By Dick Ivers in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 25th February 2013, 23:37
  2. syntax error
    By malc-c in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 21st February 2010, 21:06
  3. Need help with I2C syntax problem?
    By Michael Wakileh in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 19th July 2007, 19:11
  4. Serial LCD syntax help
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 27th February 2007, 04:37
  5. IF..THEN syntax
    By scaenix in forum mel PIC BASIC Pro
    Replies: 52
    Last Post: - 20th February 2007, 12:10

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