Problem with serin

budge

Member
I am having a problem with the serin command in the attached program, it seems to hang waiting for input.
The Picaxe is (should be) communicating with a PC application running an optical disk. If I comment out the serin lines the last bit of the program, with the remote input sending commands for stop and play, works fine. If I replace the Picaxe with a PC running Hyperterminal, whenever I type an "M" I get a response back with the mode i.e. play or stop.
I am using a MAX232 buffer connected as per the Picaxe interfacing guide page 43 except using pins 1&2 rather than 0&1. I have connected a scope and can see the serout signal going to the serial Rx port of the PC but can't see anything back on the Tx side.
I am wondering if this is a hardware issue (wrongly connected?), a timing or buffering issue or just bad programming.
Can anyone suggest how to go about sorting this out please?
 

Attachments

papaof2

Senior Member
SERIN is a blocking command: it waits for whatever you have specified before continuing.
From the manual: All processing stops until the new serial byte is received.

The bigger chips (28X1, 40X1) have the option of setting a timeout with SERIN and they also have HSERIN, which does not block.

With a 14M, 28X1 or 40X1, you can use SERRXD with a timeout.

It's also possible that the data is being sent faster than the PICAXE can process it. The usual solution there is to have the sender provide a delay of a couple of milliseconds between bytes.

John
 

moxhamj

New Member
Can you post the schematic and the PC application code too?

I'm suspecting the PC application is not sending the byte that the picaxe is expecting. So the picaxe hangs. You can debug the program so it is guaranteed to send the byte. Or you can set up the PC application so it sends dummy bytes at regular intervals. The picaxe does nothing with these bytes but at least this kicks it out of "serin hang" so it can get on with its program.
 

budge

Member
Not sure how to post schematics and am unable to see or change the application code. Max232 circuit is connected as per the Picaxe interfacing diagram, nothing more complicated than that.
My program is not looking for any specific byte and would display anything that comes back. Papa's suggestion may well be correct and the data is coming back too quickly for the Picaxe to handle so by the time serin is looking for data it has already been sent! Anyone else think that may be the case?
 

hippy

Ex-Staff (retired)
I would suggest stripping thee code down to a bare minimum and attacking this incrementally -

1 ) send bytes to the PC
2 ) receive a byte from the PC, toggle a LED ( or echo with SERTXD )
3 ) receive a byte and echo it back

That should iron out any hardware issues.
 

budge

Member
Hi Hippy,
Thanks for the advice, I had tried that and found it still hung.

Going along with the idea that the PC was responding too quickly for the Picaxe, I tried using hsersetup in background. Initial testing works fine, I get the response back that I want when just requesting one piece of info. Now all I need is to get it working with both status requests and the rest of the program!

Thanks everyone for the feedback.

Happy Christmas
Bob
 
Top