PDA

View Full Version : HSERIN and internal buffer problem on 16F628



boban
- 12th February 2007, 18:49
Hello,
sorry maybe I am too stupid but seems I have a problem even with the basic operation of HSERIN to receive the data, I don't know, how to solve it.
Immagine, that I want to simple receive two variables from my terminal, I cannot manage the timming:
E.g. I want to send p123 and I want to have it in two byte variables:
in one variable the ascii code of p and in second variable the value 123.

Looks easy, what I simple tried to do:
COMMAND var byte
SERIALBYTE var byte

while 1
if (PIR1.5==1) then
HSERIN 10, jump [command, DEC SERIALBYTE]
gosub managebytes
endif
:jump
wend

The problem is, that this doesn't work and I always have in command == "p" and in SERIALBYTE = 1.
I think, that the reason is, that the buffer of the pic has only two bytes for the serial buffer, so when I sent these 4 bytes, only first two are stored and saved to the buffer and PBP is not fast enough to manage it. My PIC is working only on 3.5 Mhz..... Do you have any other idea, how could I receive safely several bytes not just 2? I cannot use other PINS then RX and TX, so the HW flow control cannot be used.

Thanks Robert

mister_e
- 12th February 2007, 19:01
how about

HSERIN 10, jump [command, DEC3 SERIALBYTE]

Could you post the whole thing here?

HenrikOlsson
- 12th February 2007, 19:14
Hi,
I was just about to make the same sugestion as Steve. But looking at the manual it actually says that if no number follows the DEC modifier it will receive as many digits as it gets. So I'd say it should work as it is (except the missing comma after jump).

Is your X-tal 3.5Mhz or 3.58Mhz? (Can't seem to find a 3.5Mhz so I'm guessing 3.58Mhz). Have you informed PBP of oscillator speed?


DEFINE OSC 3 '<---This assumes a 3.58Mhz X-tal


And how is the USART baud rate generator setup? With PBP defines or 'manual' ?

Please, try adding 3 to the DEC modifier as per Steves post and let us know if that helps. If so there seems to be an error in the manual.

/Henrik Olsson.

mister_e
- 12th February 2007, 19:32
DEC may work or not, depending how your terminal will send your data. If he send CR+LF, this will screw your data for sure.

i've tried with


Command var byte
SerialByte var byte

hserout ["---- Ready ----",13,10]
Start:
while 1
if pir1.5 then
hserin 10,jump,[Command, DEC3 SerialByte]
gosub ManageBytes
endif
Jump:
wend
goto start

ManageBytes:
hserout ["Command=",Command,_
" SerialByte=", #SerialByte,13,10,13,10]
return

And it's working just fine, with terminators (CR+LF) or not

depending of your Baudrate, 3.58 MHz may work fine or not. Worth to use the PicMultiCalc to see the error %