PDA

View Full Version : HSERIN command - Still searching for answers



electronicsuk
- 11th March 2003, 07:36
I need to make use of the USART module on a 16F627. I have tried a number of times but I can't get it to receive anything. Note that I am not bothered about transmitting. I have a feeling it's not working because I have not set some registers that relate to the USART, but I have no idea what they should be set to. I basically want to receive 2 bytes of serial data, and read them whenever I am ready. I took a look at the datasheet, but I still stand confused. If someone could give me some example code or tell me what registers to set, and what to set them to, it would be very much appreciated.

Many thanks,
Matthew

- 11th March 2003, 20:49
Hello Matthew

you can't to use a USART module on a 16f627 because this PIC has not this function.

- 11th March 2003, 21:01
1000 apologies it's false

electronicsuk
- 12th March 2003, 07:46
Well the good news is that I have the USART working now. Trouble is, I wanted to use it because it has an input buffer. I assumed it would buffer the two bytes it receives, allowing me to read them later on in the program. The HSERIN command seems to wait until it receives the data, or you can specify a timeout. Surely this is pretty much the same as using the SERIN command? My program has to continue working at the same time as receiving serial data. So, how can I do this? It doesn't look like PICBASIC will allow it. I tried specifying a timeout, but the timeout has to be very short and I still don't receive any serial data. Doesn't this really defeat the purpose of the buffer?

Perhaps i'm using the command wrong. Any help or advice is much appreciated. Perhaps I need to program this bit in ASM, trouble is I can't program in ASM.

Best regards,
Matthew

sherm
- 12th March 2003, 11:54
Hi Matthew,

Among the many consecutive projects I have running is a desire to make my own serial LCD using pbp. I have code for an asm version but that defeats the learning process in this particular case. Anyhow, in everything I've researched to date it would appear that the only truly reliable way around this problem is to use interupts. That way you are just buffering a single incoming byte, doing other stuff with your code while waiting for the next byte and so on. That will also allow you to parse those bytes once you have them while waiting for the next lot of data to arrive. I don't have any solid code for this at this time, but it is most likely the same path that you will have to take. While I haven't begun experimenting with the pbp interupt instruction set yet, from what I have read code becomes large and has a lot of overhead as a result. Sadly, asm routines may be a better answer even if intermingled into your .bas code with ASM...ENDASM

Good coding,

Sherm

electronicsuk
- 13th March 2003, 07:47
Well thanks for the advice Sherm. Still, if anyone else has ideas they would be much appreciated.

Best regards,
Matthew

- 3rd April 2003, 23:50
hello all,

the interupt thing isn't that easy .

but you can specify a very short timeout , if it has 1 char in buffer it will receive that , otherwise it will timeout.

this works for me.

grtx , arnold

tcbcats
- 9th December 2003, 06:05
I also am trying to get the example hserin code to work.
It does not seem to be correct.. (the one that uses PIR1A.5 or so)
I need a tight loop to collect bursts of serial string data @ 9600 and would like to know when the first byte enters the two byte buffer.

I was thinking of monitoring the actial input pin that is connected to the usart.... (lookin for a start bit)... that would give me fair warning that something was entering the usart.... then pop over to the hserin and wait for the byte to show. kind of a poor mans data based interupt
Has anyone done this ??

That would give me time to get back and service the usart before it overflows. I could care less knowing when it is full because it's too late.

I now use hserin with a 2 ms timeout and it works OK for now.
Is there a good book out there that gives examples of interupt use with the usart?

876 and 877 here....

tcbcats

electronicsuk
- 26th December 2003, 09:28
After some more experimentation, I've found it best to do away with the HSERIN command. Just keep an eye out for the receive flag. When it gets set, read in the RCREG register directly to a byte sized variable. If the flag is still set then read the register again for your second byte. The flag should be automatically cleared.

Matthew