PDA

View Full Version : serin2?



chriroz
- 29th October 2006, 16:13
i'm trying to receive some serial data on my pic 16f688 but it doesn't receive anything (sending data works perfectly). i'm want to blink a led on the pic on command.

I use this code to send the data from my basic stamp 2:

SEROUT S_out, 396, ["blink"]

and i use this code to receive on my pic:

SerIn2 S_in,396,[WAIT("k")]
gosub blink

what can it be?

chriroz
- 29th October 2006, 16:49
it seems to be receiving something after al.
if i use this code:
main:
SerIn2 S_in,396,[dat]
pause 100
SEROUT s_out, N2400,["1234t", dat]
goto main

and i read it out on my BS2 it says dat = 0
so it is constantly receiving "nothing" but if i use wait("k") then it wil never see the k i send...
what can it be (it's quite urgent becouse i need this code to be working tomorow)

mister_e
- 30th October 2006, 04:44
Post the whole code here!

Be sure you disable ALL analog stuff on this 'unknown' S_Pin

Internal osc or external?

Did you try to connect your BS2 to your PC?

chriroz
- 30th October 2006, 08:14
ok here is the whole code:

on the stamp:
<code>
' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM1}

dat VAR Byte
DO
SEROUT 10, 396, ["blink"]
SERIN 10, 396, [WAIT("t"), dat]
DEBUG "data: ", DEC dat, CR

PAUSE 1000
LOOP
</code>

on the pic:

<code>
define OSC 20
INCLUDE "modedefs.bas"

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

Main:
SerIn2 S_in,396,[dat]
gosub blink
SEROUT s_out, T2400,["1234t", dat]
pause 50
goto main

Blink:
high led
pause 10
low led
return
</code>

this code only returns me "data: 0" in my debugwindow, if i use the code <code>
SerIn2 S_in,396,[wait("k")]</code> on my pic and remove the <code>SERIN 10, 396, [WAIT("t"), dat] </code>on my stamp it never blinks and it keeps waiting for that "k" the osc is an external 20 mhz crystal

chriroz
- 31st October 2006, 21:08
does anyone know how to fix this? the transmitting does work from stamp to pic but it doesn't from pic to stamp. please help me.

Dave
- 31st October 2006, 21:54
chriroz, What is the value of "dat"? I don't ever see it getting set...

Dave Purola,
N8NTA

mister_e
- 1st November 2006, 05:54
this code only returns me "data: 0" in my debugwindow, if i use the code <code>
SerIn2 S_in,396,[wait("k")]</code> on my pic and remove the <code>SERIN 10, 396, [WAIT("t"), dat] </code>on my stamp it never blinks and it keeps waiting for that "k" the osc is an external 20 mhz crystal
So you didn't post the whole thing?

Are you sure you properly set the config fuses for your PIC? HS_OSC?

chriroz
- 1st November 2006, 08:25
OK, THIS IS THE WHOLE CODE:

<quote>
on the stamp:

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

dat VAR Byte
DO
SEROUT 10, 396, ["blink"]
SERIN 10, 396, [WAIT("t"), dat]
DEBUG "data: ", DEC dat, CR

PAUSE 1000
LOOP


on the pic:


define OSC 20
INCLUDE "modedefs.bas"

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

Main:
SerIn2 S_in,396,[dat]
gosub blink
SEROUT s_out, T2400,["1234t", dat]
pause 50
goto main

Blink:
high led
pause 10
low led
return
</quote>

THAT code only returns me "data: 0" in my debug window (witch is already strange.)

and if i use THIS code (the one i actually need):

</code>
on the stamp:

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

dat VAR Byte
DO
SEROUT 10, 396, ["blink"]
DEBUG "data: ", DEC dat, CR

PAUSE 1000
LOOP


on the pic:


define OSC 20
INCLUDE "modedefs.bas"

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

Main:
SerIn2 S_in,396,[wait("k")]
gosub blink
pause 50
goto main

Blink:
high led
pause 10
low led
return
</code>

than it never blinks and never sees a "k". I really need this problem solved. please post ANYTHING that might help me (i live in european time so i usely have to wait a whole night before i can read your answers and an other day before you read my posts, so post anything you got, i don't have much time left) and my config is HS (in winpic) and define OSC = 20. "dat" is the byte in witch it saves the data received from serin2, isn't it?

thanks in advance,

Chris

chriroz
- 1st November 2006, 08:36
I also tried to use an FlowPin and it didn't work. but i found out something strange. after i send my data from my stamp the pin stays high. is that normal? if i give an "low 10" command after it it will get low again

b1arrk5
- 2nd November 2006, 15:37
It looks to me like you're waiting for the letter "K" to come in from the word "blink". Picbasic will wait until it sees the letter "K", and then the next character is placed into your variable. What is the next character after the "K"? Nothing. Hence you will return the value zero. Try it without the wait, or try something like
hserin 100,,[str Variable\5\$6b]
This will take in a string of five characters, or fewer if it sees the hex value 6b, which should be the ascii value for a lower case letter "k" if I read it right. (The print is small on my ascii table, and I forgot my glasses!)

Hope this helps.

Jerry.

mister_e
- 2nd November 2006, 18:36
Try to connect your PIC to your PC to see what's happen... Use MCS serial communicator to monitor it.

chriroz
- 3rd November 2006, 10:35
in the case where i receive the zero's i don't wait for the "k" (SerIn2 S_in,396,[dat]) I just wait for anything to come in and thats a zero (witch i didn't send!). also tried to send some data AFTER the "k" but it still doesn't get to the blink code...

Can someone just give me a working code and the right winpic settings to send data from one pic16f688 @ 20MHz to an other through portc.0 on both pics? it should blink a led (@ portc.3) on both pic's one after sending and one after receiving data. so they blink synchrome.

example:
pic1: sending data (portc.0)--> blink (portc.3)--> pause --> loop

pic2: waiting for right data (portc.0)--> receiving data --> blink (portc.3) --> loop

ok, I've been patient enough but time is running out so:

I REALY need this code working. I use this code in a huge high-school project (i'm building a local positioning system) and i'm nominated for the "best project of the year" and i have to present my project for 1600 students. even without this code working they say my team will win this competition by far BUT I just want the whole thing working so PLEASE HELP ME. (I have no teachers or anyone i know that have any knowledge about this subject to help me, so that's why i came here)

sorry for my Engrish but i'm not a native (i'm dutch)