BasicMicro - Forums

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

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: hserial2 interrupts and backgrund data
PostPosted: Fri Aug 06, 2010 10:08 pm 
Offline
New User

Joined: Sat Jul 31, 2010 11:17 am
Posts: 3
I am having some trouble understanding hserial interrupts in the manuals. I am developing a remot control application with Xbee and two atom pros (40 and arc32). My system works well but I know it can work better and faster. I want to use the interrupt to rx data in the background, process it and send the new data to the bot. I could use some program samples to help me. I think I have the first part right? Can i setup a buffer for my data? How do i get data from the buffer to my main program?

Code:
'var and con
ENABLEHSERIAL2
sethserial2 h9600,h8databits,hnoparity,h1stopbits

enable SCI3_2INT_RDRF
ONINTERRUPT SCI3_2INT_RDRF,serial_query
main:
'some more code
goto main


serial_query:
'send to robot
'? hserin [str TmpSt\6]
    'Computing Checksum
    temp(0) = temp(1) ^ temp(2) ^ temp(3) ^ temp(4) ^ temp(5) ^ temp(6)^temp(7)^temp(8)^temp(9)
           
        if  TmpSt(0)="R" and TmpSt(1) ="d" then   ' is the robot asking new data ?
            hserout ,[str temp\10]                  'sending Checksum and new datas
endif

return



:?:


Top
 Profile  
 
 Post subject: Re: hserial2 interrupts and background data
PostPosted: Sat Aug 07, 2010 7:01 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 528
Hi, Nathan can probably answer this better than I can, but I will try... I use HSERIAL on several robots with XBees and the DIY remote control that I converted to XBees (details up on Lynxmotion forums) Note: I use hserial2 on Arc32

You have a couple of choices here. When you enable HSERIAL, it installs it's own interrupt handlers for the hardware serial port. It automatically does buffer your input and output into queues. As it uses hardware serial interrupts, your program can not set and use them at the same time...

There are several tricks you can do here. What I do in my main processing when it is convenient for me is to check to see if I have any data waiting for me. If so I go and process it. There are a few different ways to doing this.
a) hserstat command - For some reason I have had problems with this in the past.
b) Roll my own, with assembly language.
Code:
   bHSerinHasData var byte
      mov.b   @_HSERINSTART, r0l
      mov.b   @_HSERINEND, r0h
      sub.b   r0h, r0l
      mov.b   r0l, @BHSERINHASDATA
      if   (not bHSerinHasData) then
         return 0

Note The variables for hserial2 looks like _HSERIN2START...
c) You do an HSerin of 1 byte with a zero timeout. Obviously you will probably need to set it up such that you can process that byte..

Or if you really do want to do everything in the background, then you will need to write your own equivalent of the HSERIAL subsystem. That is you don't define that you are using HSERIAL. You define your own handlers and then you need to write your own init code that enables those interrupts, sets the appropriate baud rates and other like options and enable the transmitter and receiver... (I would not recommend).

Good Luck
Kurt


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 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