PDA

View Full Version : serin Bug on PIC16f688?



chriroz
- 6th November 2006, 16:23
I still have a problem receiving data with my my pic16f688. I can send data (serout or serout2) but i can't receive it (serin or serin2) . does anyone else have this problem OR know how to solve it? (sorry for reposting it but i just need this to be solved, i've been patient enough but time is running out)

Dick Ivers
- 7th November 2006, 02:45
Yes, I use serin on the 16f688, and it seems to work. What pin is your serin input? Do you have a pullup resistor on that pin or have you activated the pic's internal pullup? What goes wrong when you try serin?

chriroz
- 7th November 2006, 07:02
i use PORTC.0 (pin10) or PORTC.1 (pin 9) (I tried both).I don't use pullups (YET :)). What does that pullup resistor do and how do i activate internal pullup?

chriroz
- 7th November 2006, 15:58
I connected my data wire with a 10k resistor to the ground (thats pulling down right?) and tried to use any combination of boudrates but i never see my pic blinking (so no data transmission yet...)
@stamp:


DO
FOR dat = 16000 TO 20000 STEP 1
DEBUG DEC5 dat,CR
SEROUT 10,dat, ["kk"]
NEXT

@pic


serIn2 S_in ,16780,[wait("k"),dat]
gosub blink

my pic and stamp both use the same power source so that can't be the problem either. and my stamp CAN transmit to my stamp so timing must be right...

can anyone provide me a working code to make two pic16f688 communicate trough portc.1 so i can test my pics with that code.

here is my full code again:
stamp:


' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM1}

dat VAR Word

DO
FOR dat = 16000 TO 20000 STEP 1
DEBUG DEC5 dat,CR
SEROUT 10,dat, ["kk"]
NEXT

LOOP


pic:


define OSC 20


S_in var PORTC.1
S_Out var PORTC.1
Led var PORTC.3
dat var byte

init:
gosub Startblink
high led
low led
pause 500
gosub blink

Main:

SerIn2 S_in ,16780,[wait("k"),dat]
gosub blink
pause 50
goto main


Blink:
high led
pause 10
low led
return

Startblink:
for dat = 1 to 16
high led
pause 10 * (16-dat)
low led
pause 10 * (16-dat)
next
return


please help me...

chriroz
- 9th November 2006, 18:13
I'm getting a little pissed now! Why is nobody helping me? i asked a question (what are pullups and how do i enable internal pullups) that most of the people here can answer BUT NOBODY DOES. AND WHY IS ONE OF THE MOST BASIC FUNCTIONS (SERIN) NOT WORKING????? i know it must be a simple answer BUT I CAN'T figure it out alone... (i never had any lessons in electronics or uC programming becouse i'm still at highschool)

does it have anything to do with ANSEL or TRISC?
can anyone post or send me a WORKING code for a 16f688 that uses SERIN(2)

BigWumpus
- 9th November 2006, 19:45
OK, you are pissed ?????

1.
Use your brain !

2.
The sender works to fast! He sends maybe the lowbyte of the word "dat" followed by "kk".
The receiver waits for one "k" and receives another byte. wrong order ?
Then the LED is 10ms on.

3.
Using software-UART paused by blinking and waiting needs a very slow sender with pauses between the characters.

4.
Use Hardware-UART inside a Interrupt-routine.

chriroz
- 10th November 2006, 08:48
I'm still pissed, and BigWumpus is an perfect example why:


The sender works to fast! He sends maybe the lowbyte of the word "dat" followed by "kk".
in this case "dat" is the boudrate. i tried every single boudrate between 16000 and 20000 because i thought there may be a timing problem. (it didn't work)


wrong order ?
Then the LED is 10ms on.
I WISH IT WAS ON because then it would have received a "k" and it would have PASSED the serin2 code. like i said before many times IT NEVER BLINKS.



Using software-UART paused by blinking and waiting needs a very slow sender with pauses between the characters. I also tried the code
serIn2 S_in ,16780,[wait("k")] on my pic in combination with

do
SEROUT 10,16780, ["k"]
pause 1000
loop on my stamp. i think that 1 second between the characters may be enough. (i also said this before) if i switch the codes (with a few little changes (http://www.melabs.com/resources/pbpmanual/10_0.htm)) from pic to stamp and otherwise THEN my stamp will pass the serin code if my pic sends a "k" and blink. WHY doesn't the stamp --> pic version work?



PLEASE read my post before you reply and say i'm stupid. This is a little part of my LPS project that WON the school price with over 300 students that also made projects, i'm also nominated for the National price. so i'm not stupid BUT i don't have any teachers or other people that can help me with problems like this and this is my FIRST project with picbasic EVER so i may not know some very basic things (like internal pullups). Just keep that in mind before you post...

sayzer
- 10th November 2006, 09:55
chriroz,


"Use your brain !

That does not mean you are stupid.

You should not take it personal.

One thing I wonder is that "
...i don't have any teachers or other people that can help me with problems like this...

How do they evaluate your project then?

---------------------------------------

chriroz
- 10th November 2006, 10:20
How do they evaluate you project then? well this is only a small part of my project and they can understand the code (that's not very hard) but they cant make it up.

HenrikOlsson
- 10th November 2006, 11:03
Hi,
Not known to be working but here goes....

Oh, you do use an external X-tal, not the internal OSC, right?

First we need to set the pins to digital (datasheet section 4.2.1):


ANSEL = 0 'Turn off analog inputs.

Then we need to turn off the comparators (datasheet Register 7.1):


CMCON = 7 'Turn off all comparators.

Now set PortC.1 as input and PortC.3 as output (datasheet section 4.3):


TRISC.1 = 1 'PortC.1 (pin9) as input
TRISC.3 = 0 'PortC.3 (pin7) as ouput

Then set up OSC, variables etc and then the rest:


DEFINE OSC 20 'Or whatever your X-tal is....

LED var PortC.3 'LED connected here
S_In var PortC.1 'Pin for serial INPUT

dat var byte 'Storage for received data

Main:
SerIn2 S_in, 16780, [wait("k"), dat]
Gosub blink
pause 50
goto main

Blink:
High LED
Pause 50 'Just made the pulse a little longer here
Low LED
Return


Now make SURE you program your STAMP or other PIC to send data at 2400 baud, inverted, no parity. And that you only send two bytes, first the ASCII representation of "k" and then your "dat" variable.It's been a long time since I used any of the STAMP's so I can't help you there.

That's about the best I can do without actuall hardware to test with. If it works, great! If it doesn't, don't say I didn't try.

I did see in one of you earlier posts that you had S_In and S_Out set to the same PIC pin. Is it supposed to be like that or is that an error?

By the way, pullup are when you connect a pin to the supply rail via a resistor and pulldown when you connect a pin to ground via a resistor. Some of the PIC pins have internal pullups that can be turned on and off. The 16F688's have internal pullups on PortA (except PortA.3) that you can turn on or off by configuring the WPUA register. (Datasheet section 4.2.2). PortC does not have internal pullups on the 16F688.

/Henrik Olsson.

PS. Sorry you're pissed off but you have to understand that nobody here is obligated to help anybody. We are all here on our free time and we all have our own projects, work, life, other hobbies etc.

chriroz
- 10th November 2006, 15:05
Thanks a lot. i'm gona test it right now.
and that pissed of thing was because everyone told and asked me things i already posted and that costs me an other day and i didn't had much time to fix it. Ill let you know if it works

chriroz
- 10th November 2006, 15:34
YEAH!!!!! IT WORKS finally after 2 weeks of trying it works :D
HenrikOlsson's code worked except for

CMCON = 7 'Turn off all comparators.
it gave me an undefined symbol 'cmcon' error but after some searching i saw that
POKE $19, 7 would do the same thing
and it did :D
THANK YOU SO MUCH!! (HenrikOlsson, you don't mind I put your name in my project references?)

HenrikOlsson
- 10th November 2006, 15:54
Hi,
No problem, glad you got it working!
I completely forgot about the CMCON thing even though I read it just the other day. As you probably also found out, there are patches available, depending on the version of your PBP:

http://www.melabs.com/support/patches.htm

Good luck with the rest of the project.

/Henrik Olsson.