PDA

View Full Version : serial trouble



ronjodu
- 22nd November 2004, 00:04
I've tried several things but the problem is still unresolved.
I am receiving serial with this command:

SerIn2 PORTA.0, 84, 100, loop, [rtcday] 'put day byte in rtcday


That works perfectly.
When I try:

SerIn2 PORTC.7, 84, 100, loop, [rtcday] 'put day byte in rtcday

I get nothing.
I've tried HSERIN also to no avail.

As usual it's probably something simple. I've read many previous posts about serin2 and havn't seen the answer.

Any comments would be appreciated.
Thanks in advance for any help....


16f876, PBP, 4mhz

hmr
- 22nd November 2004, 05:24
Hi Ronjodu,

You didn't post all your code but as the 16F876 is analog input on PORT A and all MCU with analog input comes up in analog mode you have to set it to digital before using it.

Try to add in the begin of your code:

ADCON1=7

I hope this solve your problem.

Hans

mister_e
- 22nd November 2004, 18:19
SerIn2 PORTC.7, 84, 100, loop, [rtcday] 'put day byte in rtcday

I get nothing.
I've tried HSERIN also to no avail.


solution is simple. You're using 4MHZ crystal to run 9600 baud.. it will not working properly. You must use higher speed crystal (20Mhz) or lowest baudrate (2400 baud).

if you're using 20MHZ crystal don't forget in add
DEFINE OSC 20

and program your chip to HS oscillator mode.

regards

P.S. HSERIN work as inverted signal, must use transistor or MAX232 to invert signal.

ronjodu
- 22nd November 2004, 23:43
Thanks hmr and Mister_E for the response. I did have ADCON1 = 7 already. As I mentioned the serin2 worked when on PORTA.0.

I assumed that I would only need to change the port address to PORTC.7 and all would work the same as if I had it on PORTA.0..

I did try changing the baud to 2400 on the send (Siteplayer) and the receive(PIC) sides.

To do this I changed the Siteplayer baud to:
(Baud dw 65015 ( for those who might know siteplayer))
And the pic command to:
SerIn2 PORTC.7, 396, 100, loop, [decdate]

Still no luck.
I have a pulldown 2.2K resistor on the Siteplayer transmit line. This doesn't seem to bother the PORTA.0 receive.

I'm open to all suggestions.
Thanks again all...

I'm editing this post because I have made some progress..
It seems Siteplayer didn't change it's baud rate as I expected. I now have 2400 Xmit and Receive on both sides.
I am getting data however it is not accurate. The numbers coming thru are wacked.

mister_e
- 23rd November 2004, 00:09
what about if you remove TimeOut label???
what about if you try an pullup instead???

Are you sure voltage swing is correct for serial data. What about if you place an buffer between PIC and SitePlayer

One thing is weird here.... work on PORTA not on PORTC... by a pure guess did you declare

TRISC=255 ;portc as input???

since PORTC is multiplexed with a load of peripheral function, it seems that is safe to do it. As a safe i always declare I/o directions..

what about if you use SERIN or HSERIN without any timeout instead of SERIN2???

ronjodu
- 23rd November 2004, 00:19
I have declared the following:

TRISA = %00111111 'Set PORTA RA0-RA5 to input
TRISB = %00000000 'Set PORTB to all output
PORTB = %00000000 'Set all outputs to 0 (off)
TRISC = %10000000 'Set PORTC to all output except #7
PORTC = %00000000 'Set all outputs to 0 (off)

I've tried serin and hserin but maybe the baud change will help. I'll try again in a bit. (Kid's hockey practice for now.)
Probably the only hockey I'll see this year!!!

Thanks again for the input...

mister_e
- 23rd November 2004, 02:04
not sure but if you declare
TRISC = %10000000 'Set PORTC to all output except #7
PORTC = %00000000 'Set all outputs to 0 (off)


PORTC=%00000000
will make PORTC.7 as output.... not sure of this. Try to remove PORTC= line.

if data if wacked, maybe because of the Timeout label.

regards

ronjodu
- 28th November 2004, 23:29
Hello again, sorry for the delay. Busy Holiday, no time.
I've tried removing the timeout, no change. I did notice the data I was sending to the LCD was double what I expected.
In other words I expect :
"11/28/04" but got "22/56/08".

I am now dividing the variable by 2 before sending to the LCD.

The LCD now displays what I expect.

My Question! Why, when I use:
SerIn2 PORTA.0, 396, [decday]
It works but when I use :
SerIn2 PORTC.7,396,[decday]
I have to divide the variable by 2?

I've included my code. Go easy on me it's one of my first projects.