BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 8:02 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: hserstat
PostPosted: Wed Feb 02, 2011 8:12 pm 
Offline
Master

Joined: Sun Oct 05, 2008 9:40 am
Posts: 111
I am looking for information on using hserstat. This is what I have found post40930.html?hilit=hserstat#p40930

I tried this but no go

Code:
sethserial1 h9600
info var byte

low p0
low p3

pause 500

hserout ["Program Running",13]

main:

hserstat 3, check   
hserout ["No Info ?",13]

goto main

check:

hserin 0, [info]

if info = "a" then
  high p3
 
elseif info = "b"
low p3

else
toggle p0

endif

goto main


Suggestions on using Hserstat and defining which uart?


Top
 Profile  
 
 Post subject: Re: hserstat
PostPosted: Thu Feb 03, 2011 7:20 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
From email I received from Nathan:
AcidTech wrote:
HSERSTAT mode arguments now include the choice of uart 1 or uart 2.

modes 0 to 7 are the same as before but are specifically for uart1. Then 8 to 15 are the same modes but for uart 2.


From Some older manuals I had:
Quote:
HSERSTAT
The HSERSTAT command lets you check the status and/or clear the
hardware serial port buffers. Before using this command you must
use the SETHSERIAL command (see page 122) to set the correct
baud rate.
Also, before using the HSERSTAT command, a program must use
the ENABLEHSERIAL command. The ENABLEHSERIAL command
enables serial communications, and is required for the HSERSTAT,
HSERIN, and HSEROUT commands.
Syntax
hserstat funct{,label}
funct is a value from 0 to 6 that determines the function of the
hserstat command according to the following list:
Value Function
0 Clear input buffer
1 Clear output buffer
2 Clear both buffers
3 If input data is available go to label
4 If input data is not available go to label
5 If output data is being sent go to label
6 If output data is not being sent go to label
label is an optional argument (use with values 3 – 6) that
specifies the destination jump address.
Examples
The following example will wait for input data to be available before
continuing, then input 3 bytes of data from the hardware serial port.
ant var byte
bat var byte
cat var byte
enablehserial
sethserial h2400 ; 2400 baud
hserstat 0 ; clear input buffer
getdata
hserstat 4, getdata ; loop if no data in buffer
hserin [ant,bat,cat] ; get 3 bytes of data

The following example will wait for all data to be sent before
continuing program execution. The variable "ant" is a 20 element
array which has been defined and populated.
enablehserial
sethserial h2400 ; 2400 baud
for x = 0 to 19
hserout [ant(x)] ; output the array contents
next
notyet
hserstat 5, notyet ; wait until all data is sent
Since data output may be slower than program execution, it may be
necessary to wait before proceeding, depending on program and
peripheral devices

Nathan mentioned in the email 0-7 for UART1... Not sure what 7 is...

Note: earlier when I tried to use hserstat to check for input available, I had problems with the program resetting. Not sure why it is a very simple function, so I rolled my own. Since then Nathan worked on the SSC-32 emulation for Arc32 and added a new function (hserinnext), which is followed by an argument. If the argument is a 1 or 2 this says to get the next character from the specified hardware serial port, if none is available it will wait. If the argument is 0x81 or 0x82 it says to return the first character from the queue. If none is available it will return -1 and not wait... So for example in my XBee code I have a function to return the next packet of data. At the start it has:
Code:
_fapiWaitForInput   var   byte
APIRecvPacket[_fapiWaitForInput]:

   ' First see if the user wants us to wait for input or not
   ;   hserstat HSERSTAT_INPUT_EMPTY, _TP_Timeout         ; if no input available quickly jump out.
   ; Well Hserstat is failing, try rolling our own.
   if not _fapiWaitForInput then
      ; use the new hserinnext instead of assembly to see if there is input...
#ifdef BASICATOMPRO28
      if (hserinnext 0x81) = -1 then
#else
      if (hserinnext 0x82) = -1 then
#endif
         return 0;
      endif
   endif   

I hope that helps

Kurt


Top
 Profile  
 
 Post subject: Re: hserstat
PostPosted: Thu Feb 03, 2011 8:51 am 
Offline
Master

Joined: Sun Oct 05, 2008 9:40 am
Posts: 111
Help it did thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO