PDA

View Full Version : explanation about HSERIN command!



DeViLa_Q8
- 31st August 2009, 14:42
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,,

Archangel
- 1st September 2009, 05:29
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:


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

mackrackit
- 1st September 2009, 08:27
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

DeViLa_Q8
- 2nd September 2009, 20:33
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,

DeViLa_Q8
- 2nd September 2009, 20:38
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

mackrackit
- 2nd September 2009, 23:08
Can you tell us what you are sending and the result?
Also, how is your hardware set up?

DeViLa_Q8
- 3rd September 2009, 00:09
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...

mackrackit
- 3rd September 2009, 02:36
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/rs422_485_app_note/table_of_contents.asp

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

Post your whole code so we can take a look.

DeViLa_Q8
- 5th September 2009, 15:32
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...