PDA

View Full Version : SERIN and SEROUT



CumQuaT
- 1st September 2009, 02:31
Hi all,

First post here, hopefully one of many (helping as well as getting help)

I have a question that I'm sure has a very simple answer, but I'm having trouble with it. I've got a situation where I need to use multiple PICs in a project (I'm working with the PIC16F628A on a 4MHz XTAL) and I need them to be able to send data to one another. One will only send data and one will only receive data. Nothing fancy, it only needs to send a single digit number.

What I'd like to know is, what is some basic code to put on PIC A and PIC B to get PIC A to send numbers 0 to 3 via SEROUT and have PIC B recognise those numbers and, say, light up an appropriate LED. Currently I'm using the following code:

'PIC A (Sender)
INCLUDE "modedefs.bas"

x VAR byte

main:
FOR x = 0 to 3
SEROUT PORTB.0, T2400, [x]
PAUSE 1000
NEXT
GOTO main


'PIC B (receiver)
INCLUDE "modedefs.bas"

x VAR byte

main:
SERIN PORTB.0, T2400, [x]
IF x = 0 THEN HIGH PORTB.1
IF x = 1 THEN HIGH PORTB.2
IF x = 2 THEN HIGH PORTB.3
IF x = 3 THEN HIGH PORTB.4
GOTO main


I'm aware it may also be a wiring issue... I just have a straight wire (I'm breadboarding this first) going from PORTB.0 on PIC A to PORTB.0 on PIC B.

Anyone have some advice?

Thanks in advance!

Archangel
- 1st September 2009, 05:18
Hello CumQuaT,
Welcome to the forum.


Anyone have some advice?

You could start by telling us what kind of problem you are having . . . DOA . . . ?
A couple of things, DEFINE OSC 4 near the top of your code.
If you are not using analog on PortA add cmcon = 7 to disable the comparators there so it doesn't trip you later.
Set up your Ports as high or low before setting your TRIS registers, and do not skip setting those.


'a config statement should go here unless default config is just right
DEFINE OSC 4
cmcon = 7
PortA = 0
PortB = 0 set all output latches low
TrisA = %00000000 'set PortA as all outputs
TrisB = %11100000 '5,6,7 as inputs all others as outputs
Main:
' . . . . your code goes here
goto Main
end

EDIT: Serial data, True idles high, and wants a pull up resistor on the data line to 5v +
Inverted idles LOW and wants a resistor pulling to logic LOW or ground.

CumQuaT
- 1st September 2009, 05:34
Hi! Thanks for the warm welcome!

I actually described precisely what my problem is. The code I have with the connections I have isn't transmitting or receiving single numbers. I am also not using porta at all in my code.

aratti
- 1st September 2009, 07:49
See page 131 of PBP manual. Since you have used bracket pic is waiting for QUALIFIER first. Remove brackets from SERIN.

SERIN PORTB.0,T2400,x

Follow Joe advice on the setting even if you don't use PortA.

mackrackit
- 1st September 2009, 08:35
All the above and


I'm aware it may also be a wiring issue... I just have a straight wire (I'm breadboarding this first) going from PORTB.0 on PIC A to PORTB.0 on PIC B.
You also have the "grounds" connected? Two wires are needed. :)

CumQuaT
- 1st September 2009, 10:07
You mean the grounds to the PIC? As in VSS? Or are there grounds required in regards to wiring the two pics together in serial?

mackrackit
- 1st September 2009, 10:17
You mean the grounds to the PIC? As in VSS? Or are there grounds required in regards to wiring the two pics together in serial?

Yep, VSS. The way you had it worded "a straight wire" made me think you may not have two.

Archangel
- 2nd September 2009, 04:47
Hi! Thanks for the warm welcome!

I actually described precisely what my problem is. The code I have with the connections I have isn't transmitting or receiving single numbers. I am also not using porta at all in my code.I must be getting senile . . . single numbers . . . or anything usable (DATA), if you send a string does that show up ? Or do you get nothing at all ? Do your Pics do anything? Do you have a heartbeat LED on them to ascertain they are actually working?
As mentioned above serial is 2 wire signal and ground, coax or twisted works fine, (doorbell wire makes for cheap twisted pair).
Question: Are you using a resonator / crystal / or INternal RC Oscillator ? Do the default config statements located in the 16F628A.inc file in the PBC root directory agree with what you are trying to use? Are you using PBC or PBP ?

hatchethand1000
- 2nd September 2009, 21:30
Has anyone see a change on the SERIN command with ver 2.60 upgrade?

I had this command working fine with v2.50a and now it will not work on 2.6

Any ideads? the ON9600 seems to be the issue.


Serin PORTC.5,ON9600,B0

Thanks,
Kevin

mackrackit
- 2nd September 2009, 23:14
Has anyone see a change on the SERIN command with ver 2.60 upgrade?

I had this command working fine with v2.50a and now it will not work on 2.6

Any ideads? the ON9600 seems to be the issue.


Serin PORTC.5,ON9600,B0

Thanks,
Kevin

Is this new code or old code that worked with 2.5?
Did you remember to include modefs.bas?
Can you find the new thread button?

CumQuaT
- 3rd September 2009, 00:17
Hi all,

I resolved the issue. I just had to remove the brackets when using SERIN. Aratti was right.

Thanks for the help!