explanation about HSERIN command!


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2009
    Posts
    6

    Default explanation about HSERIN command!

    dear all,
    IF i send four digits refer to the status of my LEDs from several PICs(18F877A) and recieve them using HSERIN command one after another using subroutines..
    May this affect accuracy of the sent data? are there any further configuration for the HSERIN command in this case? Is there a way to clear the buffer after each sending ( because it keeps showing me the same result each time i send new values).
    thank you,,

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi DeViLa_Q8,
    Hard to answer as to what more you need, as you did not show us how you set up the hserin to work. As far as clearing the buffer goes, read it into another variable and then zero it before the next read.
    example:
    Code:
    char var byte
    dummy var byte
    Main:
    HSERIN char
    info = char
    char = 0
    ' . . . . do something with info . . LCDOUT #info ?
    goto main
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Maybe this will help?
    From the manual
    As the hardware serial port only has a 2 byte input buffer, it can easily overflow if characters are not read from it often enough. When this happens, the USART stops accepting new characters and needs to be reset. This overflow error can be reset by toggling the CREN bit in the RCSTA register. A DEFINE can be used to automatically clear this error. However, you will not know that an error has occurred and characters may have been lost.

    *** DEFINE HSER_ CLROERR*** 1

    To manually clear an overrun error:

    *** RCSTA. 4 = 0*
    *** RCSTA. 4 = 1
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Jul 2009
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Hi DeViLa_Q8,
    Hard to answer as to what more you need, as you did not show us how you set up the hserin to work. As far as clearing the buffer goes, read it into another variable and then zero it before the next read.
    example:
    Code:

    char var byte
    dummy var byte
    Main:
    HSERIN char
    info = char
    char = 0
    ' . . . . do something with info . . LCDOUT #info ?
    goto main

    dear Joe S.
    I'm working on this code using the new ideas and i hope it'll work anyway In case the idea was not that obvious

    the first HSERIN will be like this,


    HserIN [WAIT("OK"),TARGET]
    IF TARGET ="A" THEN gosub check1
    ..........

    after it'll compare the result then it'll perform subroutines attached to each target and in this subroutine there's another HSERIN which is,

    check1:
    HSERIN [X,Y,Z,M,N] ' analog
    ......
    statements
    .....

    i traced my code it working great and i tested it on LCDs except the previous HSERIN result it's totally not correct.i hope it becomes clear now.

    thanks for yr help,

  5. #5
    Join Date
    Jul 2009
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    Maybe this will help?
    From the manual
    Quote:
    As the hardware serial port only has a 2 byte input buffer, it can easily overflow if characters are not read from it often enough. When this happens, the USART stops accepting new characters and needs to be reset. This overflow error can be reset by toggling the CREN bit in the RCSTA register. A DEFINE can be used to automatically clear this error. However, you will not know that an error has occurred and characters may have been lost.

    *** DEFINE HSER_ CLROERR*** 1

    To manually clear an overrun error:

    *** RCSTA. 4 = 0*
    *** RCSTA. 4 = 1

    dear mackrackit,

    I changed the code to manually clear the buffer,but unfortunately it gives the same incorrect result as before .

    thank you for yr help,



    dear

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Can you tell us what you are sending and the result?
    Also, how is your hardware set up?
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Jul 2009
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    hi mackrackit,

    Also, how is your hardware set up?
    three PICs are attached to a master PIC all of type 16F877A using RS-485.

    configuration without leds lcd definitions :

    * MASTER PIC:



    Include "Modedefs.bas"
    DEFINE OSC 4
    DE_OR_RE VAR PORTC.5
    RS232_DEBUG_PIN VAR PORTB.5
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 20h
    DEFINE HSER_SPBRG 25
    DEFINE HSER_BAUD 2400
    DEFINE HSER_CLROERR 1
    OPTION_REG.7 = 0
    CMCON = 7
    ADCON1 = 7
    B0 = 0

    SLave PIC:

    Include "Modedefs.bas"
    DE_OR_RE VAR PORTC.5
    DEFINE HSER_RCSTA 90h
    define HSER_TXSTA 20h
    define HSER_SPBRG 25 'SPBRG 2400
    DEFINE HSER_BAUD 2400
    DEFINE HSER_CLROERR 1
    DEFINE OSC 4 ' We're using a 4 MHz oscillator
    DEFINE ADC_BITS 8 ' Set A/D for 8-bit operation
    DEFINE ADC_CLOCK 1 ' Set A/D clock Fosc/8
    DEFINE ADC_SAMPLEUS 50 ' Set A/D sampling time @ 50 uS
    TRISA = %11111111
    PORTA = %00000000
    OPTION_REG.7 = 0
    CMCON = 7
    ADCON1 = 0


    Can you tell us what you are sending and the result?
    i'm sending from another PIC 1's and 0's which represent the status of my sensors it's attached on analog pins(four sensors for each slave PIC).
    The result should be also received as 1's and 0's as sent in sequence.

    thanks for help...

  8. #8
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    485 ....
    Have you enabled/disabled the TX pin?
    If you are not familiar with 485 this is a good read
    http://www.bb-elec.com/tech_articles...f_contents.asp

    And buried in this thread is some code.
    http://list.picbasic.com/forum/messa...html?996705165

    Post your whole code so we can take a look.
    Dave
    Always wear safety glasses while programming.

  9. #9
    Join Date
    Jul 2009
    Posts
    6


    Did you find this post helpful? Yes | No

    Default

    hi mackrackit,
    sorry for being late but i had some wrok to do the previous days..
    here're the full code attached down, so it'll be easier to detect the errors.

    Have you enabled/disabled the TX pin?
    yea, i'm already receiving and sending but my problem is the incorrect received values.

    thanks alot...
    Attached Files Attached Files

Similar Threads

  1. explanation on I2C command (PBP)
    By F1CHF in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 12th May 2014, 05:30
  2. Active low input?
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 8th August 2010, 20:31
  3. HSERIN and XOUT command
    By aratti in forum General
    Replies: 20
    Last Post: - 12th May 2009, 11:58
  4. Can I do this???
    By noobie in forum mel PIC BASIC
    Replies: 2
    Last Post: - 10th June 2006, 18:57
  5. HSERIN command - Still searching for answers
    By electronicsuk in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 26th December 2003, 09:28

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