need help combining serial in and out with infra

budge

Member
I have a project where I want to use a PICAXE as a dumb terminal interface to an application on a PC which controls an optical drive. The control commands are simply "P" for play or "S" for stop which I would like to instigate from a PICAXE remote control using infra red. Mode and track status, requested by the PICAXE approximately twice a second using a "M" or "T", will be received as a serial string ending with a null byte then the appropriate bytes will be displayed on a serial LCD.
My problems are mainly knowing which PICAXE to select and how to handle the serial status input.
The problem with the chip is the serial speed needed for the PC is 9600, the serial display 2400 and the infra red input where I intend to use irin [400,main]etc.
The problem with the serial input string is that I have never done anything with serial input and am not sure where to put a string of up to 14 bytes and if I can just buffer the string then look for the null byte or if there is time to check for it as the string goes in.
I did start to program this before going into hospital three weeks ago for a major (10 hour!) operation and am just starting to think about it again but don't have the concentration span at the moment so any help to get me started in the right direction would be greatly appreciated.
Thanks
Bob
 

westaust55

Moderator
Please look at the SERTXD command in the PICAXE manual 2 (page 153)

then look at the SETFREQ command on page 160.

Any PICAXE that can be set to 8MHz (default on energisation = 4MH)
can communicate at 9600Baud.
 

budge

Member
Need help with serial input

I am thinking that my first post was too vague for a detailed reply but thanks WESTAUST55 for the guidance.

Having gone back over some of the ground, in order to use IRIN I need a 28X and that will support both 2400 and 9600 at 8mhz so that is my choice of chip.

My main problem is understanding how to receive approximately 14 bytes of data coming back from the PC, where to put them and if there is time at 9600 to check for a null character as each byte comes in. I have a vague understanding of the ptr,ptrinc commands and intend to use them unless someone has a better idea. If there isn't enough time to check for null character as the bytes come in perhaps it would be as well to use the hserin command.

All advice very welcome.
 

lbenson

Senior Member
If you are using a 28X1 anyway, for serial in you can use hserin (along with hsersetup) to have the serial input received in the background and placed in the scratchpad memory. Your code can check hserinflag to see if input has arrived and hserptr to see how many bytes have arrived.

hsersetup sets up the fixed serial port:

hsersetup B2400_4, %1 ' set up background receive (on I7, leg 18)

A loop of this sort can be used to pick up the data

Code:
  ptr = 0
  do     
    b1 = @ptrinc ' now do something with b1
  loop while ptr < hserptr
When you have finished processing an input string, you must reset hserinflag (and hserptr unless you want the scratchpad to act as a ring buffer--I haven't tried that).
 
Top