Background serial receive question

kakolon

Member
Hi,
I need to get serial data from a PC, this serial data is a fixed print information that goes to a serial printer.
The picaxe will be in between the PC and the serial Printer, it will get the serial data output from the PC, then it will change some bytes, and then it will send it to the serial printer.
I am using a 40 X1 picaxe to capture the bytes. I want to use Background serial receive, and here is the question, I read the example code that Technical made in August, explaining how you have to do a loop and check if hserinflag = 1 to know data has arrived. OK. I suppose that when the first byte arrives, the hserinflag turns to 1, if you are receiving various bytes, then when you go to the scratchpad, resetting the pointer and looking at the byte received, there might be other bytes arriving at the same time you are doing this.
Does this matter ?, Will I mess the scratchpad and loose bytes ?.
Would it be a good idea to wait for some time after the hserinflag has been turned to 1, so I would be sure no more data has arrived before I go to the scrathpad?

Thanks,
Kakolon
 

Technical

Technical Support
Staff member
The flag is set every time a byte is received.

However the pointer to the scratchpad (hserptr) also increments every time a byte is received, so by reading the hserptr value you know how many bytes have been received.
 

lbenson

Senior Member
To modulate the flow of characters from your PC, you might need to assert a Clear to Send (CTS) signal to the PC, and de-assert it to stop the PC from sending more than you can handle. If you can handle each character before the next one arrives, or all before the scratchpad overflows, that would not be necessary.

I used hserin on a 28X1 to get data from a SimpleLan internet module, but the module only sends data when you request it, and in a size that won't overflow the scratchpad. After requesting the data, I paused for long enough for the longest message (64 bytes) to be sent.

If you need to read up on RS232, the wikipedia article is not bad:
http://en.wikipedia.org/wiki/RS-232
 

kakolon

Member
Thanks for the information,
I have another question, I using SERIN to get one byte from the PC (using terminal program), I can only get correct bytes when I use 2400 speed, if I use a higher speed, the data arrives corrupt. What could be happening?. I have used SERIN at 9600 to read from a codebar scanner without problems in a 18X, the chip I'm using now for this test is a 40X1.
 
Top