Scan the serial input?

RogerTango

Senior Member
Back in the C-64 days, we were able to scan the keyboard buffer for key press using PEEKs.

I wonder... since SERIN cannot scan, it must halt until data is received, is there a way to scan the serial input buffer for data and then process it?

I ask because I want the chip to continue with other task, all the while checking for serial data to take it to a menu or whatever...

This kind of leads me to... Is there a chart, doc, PDF or whitepaper anywhere that outlines mem addresses for the various AXE chips and what they are for (memory map with comments)?

Thanks,
Andrew
 

Jeremy Leach

Senior Member
You need to take a look at the manuals really Andrew ....well worth a read and very clear IMHO.

Serin or Serrxd command receive data and put it directly into variables - no buffer involved (there might be one used at a low level but I don't think it's accessable).

HSerin command can put data into a 'scratchpad' on certain picaxes, (e.g 28X1). The scratchpad acts as a buffer, and you can use the 'get' command or @ptr variable to extract data from the scratchpad (rather than peek). You can make this reception happen automatically in the background (see Hsersetup command) where data automatically gets dumped to the scratchpad. This automatic reception can be set to generate an interrupt so your picaxe code can go and inspect the data immediately it's started to arrive.

"PICAXE Manual 1 - Getting Started" has a section 'Understanding the PICAXE memory'. And manual 2 gives comprehensive descriptions of the serin, serout, hserin, hsersetup commands etc.
 

moxhamj

New Member
"I wonder... since SERIN cannot scan, it must halt until data is received, is there a way to scan the serial input buffer for data and then process it?"

Not on most picaxes. Only the high end (expensive) ones.

Serin will read as many bytes as you like into b0 variables, and you could certainly read them one at a time into b0, then go and do something with that variable, then come back and do another serin. But that assumes long pauses between each byte coming through.

The serin hang is a total pain. No workaround is very satisfactory. I've written my own slow serial code, and used pulsin and pulusout instead - in fact any other picaxe command will timeout. You can use a common bus and have one picaxe that just puts dummy packets on the bus from time to time to kick other picaxes out of serin hangs.

You can have one picaxe turning another on and off - and get the second one out of serin hang that way.

What is your application - maybe we can come up with a cunning workaround?
 

RogerTango

Senior Member
Thanks Doc for the help-

I dont have a particular app in mind at the present, however I know I will be wanting to scan the serial in for the presence of data. Since AFAIK the serin will pause until it receives data, the chip is "locked" until something is sent.

I want the chip to be operational with the program, each loop in the MAIN loop it checks for "did something come into the serial port? If so, lets go to the input routine and get a command, which will be following this 'attention signal'"

I hope I am making sense. I dont necessarly need to know WHAT is sent, just send a 'I am sending a transmission to be read next, this is just an alert'.

The objective is, while the AXE is executing, Ill want to be able to plug up a laptop or PPC with serial and run terminal, send something (maybe 'hello' just for giggles, it wont matter what you send, its just an attention signal), when it sees something was sent, it will go to a "main menu", print the main menu on the screen and THEN get valid data to process.


Thanks,
Andrew
 

leftyretro

New Member
Thanks Doc for the help-

I dont have a particular app in mind at the present, however I know I will be wanting to scan the serial in for the presence of data. Since AFAIK the serin will pause until it receives data, the chip is "locked" until something is sent.

I want the chip to be operational with the program, each loop in the MAIN loop it checks for "did something come into the serial port? If so, lets go to the input routine and get a command, which will be following this 'attention signal'"

I hope I am making sense. I dont necessarly need to know WHAT is sent, just send a 'I am sending a transmission to be read next, this is just an alert'.

The objective is, while the AXE is executing, Ill want to be able to plug up a laptop or PPC with serial and run terminal, send something (maybe 'hello' just for giggles, it wont matter what you send, its just an attention signal), when it sees something was sent, it will go to a "main menu", print the main menu on the screen and THEN get valid data to process.


Thanks,
Andrew
As Jeremy already posted, both the 28X1 and 40X1 has the feature you desire. There is a data avalible flag that you can scan and test to see if a character has been received. This is only supported in the X1 chips and only when using the Hserin command. The standard software serial command (avalible on all Picaxe chips) Serin does not support this feature and is indeed a "blocking" command that prevents further program progress until a character is received.

From the help manual:

Hardware serial input can be configured in two ways:
1) via hserin command only (mode bit0 = 0)
2) automatic in the background (mode bit0 = 1)
In automatic mode the hardware serial input is fully automated. Serial data
received by the hardware pin is saved into the scratchpad memory area as soon as
it is received. Upon the hsersetup command the serial pointer (hserptr) is reset to
0. When a byte is received it is saved to this scratchpad address, the hserptr
variable is incremented and the hserinflag flag is set (must be cleared by user
software). Therefore the value ‘hserptr -1’ indicates the last byte written, and
‘hserinflag = 1’ indiactes a byte has been received (se also the setintflags​
command). The scratchpad is a circular buffer that overflows without warning.

Lefty

 

BeanieBots

Moderator
One option worth investigating is the use of interrupts.
Setup an interrupt to trigger on your serin pin. Then only enter serin once the pin has "triggered".
 

westaust55

Moderator
Have a look at the memory map that I created:
http://www.picaxeforum.co.uk/showthread.php?t=9525&page=2

But to fully udnerstand the Special Fucntion Registers you need to look closely at the relevant PIC datasheet

I use the interrupt method for keypad entry on my system.

The keypad encoder chip sends a signal to indicate datais ready. this causes an interrupt and the PICAXE then inputs the data byte using SERIN. I use the E_labs EDE1188 keypad encoder chip but a 74HC922/923 and 74HC165 combo will also work.
 
Last edited:

moxhamj

New Member
I'm using a solution at the moment where some serin data arrives and the chip then puts a line high to say it has arrived and another chip then gets the data from the first chip, either via serial or via another protocol which can timeout (eg a series of long or short pulsouts/pulsins). Yes the X1 parts can also do it. I'm using two 08s because they work out cheaper. Lots of different solutions. I'm not sure one is 'better' than the other. Whatever works, really.
 
Top