PDA

View Full Version : Serial Communication problem (read other topics but still have the problem)



Jcee324
- 8th November 2004, 10:06
Hello

I have a problem with serial communication between two PIC-
processors, one PIC16F84A and one PIC16F627. I uses the commands SerIn2 and SerOut2. One-way communication works fine, I can send a signal from one PIC to the other (SerIn2 on the 16F84A and SerOut2 on the 16F627) but when I tries to use both commands on both PIC's at the same time and so get a two-way communication everything stop working. Does anyone know what I can do to create a two-way serial communication between the processors?

Another small question. Can a PIC and a BasicStamp communicate
useing SerIn/SerOut? And has any of you used Parallax BOE-Bot? I am
planing of maybe buying one, is it worth the money?

Thanks for the help.
\Jonas
http://www.geocities.com/jcee324/eindex.htm

Dwayne
- 8th November 2004, 15:05
Hello Jcee,

Jc>>I have a problem with serial communication between two PIC-
processors, one PIC16F84A and one PIC16F627. I uses the commands SerIn2 and SerOut2. One-way communication works fine, I can send a signal from one PIC to the other (SerIn2 on the 16F84A and SerOut2 on the 16F627) but when I tries to use both commands on both PIC's at the same time and so get a two-way communication everything stop working.<<

Well, you have step one going! This is important. communication in one direction. Yes, everything will stop working. One serial communication must be completed before the response is sent from the other chip. The Serin takes control of that one pin, and must finish its job before a Serout take place.

Dwayne

Jcee324
- 8th November 2004, 16:37
Hello

Thanks Dwayne, I understand that you can't send in two directions at once on the same pin. But I want to communicate one way on one pin and the other way on another pin. Is that possible?

\Jonas
http://www.geocities.com/jcee324/eindex.htm

Dwayne
- 8th November 2004, 19:16
Hello Jcee,

Jcee>>Thanks Dwayne, I understand that you can't send in two directions at once on the same pin. But I want to communicate one way on one pin and the other way on another pin. Is that possible?<<

It certainly is, as long as it is not at the "exact" same time.

In other words, there should be a "trigger" byte to tell the other chip to send or receive. That trigger byte can be on the "transmit pin", or be part of the receive pin. (Depending on how you want it.)
thus it will talk back and forth just like a walkie talkie. (not like a cell phone).

Serin2 has a timeout value thus both chips can be in a loop.

tell us how you want it to work, maybe we can puts some code out there for you...

Dwayne

Jcee324
- 11th November 2004, 10:47
Hello

Well Dwayne, for the moment I don't know exactly how I want it to work. But I you (or someone else) could put a code together that just makes it possible to send a byte between the PICs (one message and one answer) it would be great, I have tried myself now a couple of days but not geting it to work. I want a continual communication (not just one message and one answer and thats it but that the PICs communicate the whole time) if it's possible.

Thanks alot!
\Jonas
http://www.geocities.com/jcee324/eindex.htm

Dwayne
- 11th November 2004, 14:56
Hello Jcee,

JCee>>Well Dwayne, for the moment I don't know exactly how I want it to work. But I you (or someone else) could put a code together that just makes it possible to send a byte between the PICs (one message and one answer) it would be great, I have tried myself now a couple of days but not geting it to work. I want a continual communication (not just one message and one answer and thats it but that the PICs communicate the whole time) if it's possible.<<

Ok, do you want one chip to be the master? The one that initiates all communication between both chips? (This is the easiest way) Or do you want both to be masters, where either one can initiate communication between each other? (this is harder).

Dwayne

Jcee324
- 11th November 2004, 17:06
Hello Dwayne

Well I think that it would work fine with one master and the other to be slave. Can you have several slaves? Not that I need it but it can be good to know in the future. What is the main difference between the programs if one or both is master?

\Jonas
http://www.geocities.com/jcee324/eindex.htm

Dwayne
- 11th November 2004, 17:36
Hello Jcee,

L>>Well I think that it would work fine with one master and the other to be slave. Can you have several slaves? Not that I need it but it can be good to know in the future. What is the main difference between the programs if one or both is master?<<

You can easily have several chips being slaves. the master "initiates" the communication, and then the communication starts.

With only one master, all the other chips are "listening" . With Two masters, both chips must be listening, and be able to transmit too.

masterchip. Psuedocode.

TRISA = "%00000001"

Tx Var Porta.0
Rx Var Porta.1

Loop:
Tx=High 'initiate transmittion
Pauseus 10 'give time for receiver to switch to receive mode
Serout Tx, 2400, ["Slave1","T"] 'make sure only Slave1 chip recevies the "T"
if Rx <> High then Loop 'Slave did not receive the "T";

Serout Tx,2400,"Transmit all my data here"
Tx=Low
end of routine.


Receiver.

Same variable setup.
RxData var byte

Loop:
while Rx <> "High" goto Loop;
Serin Rx,2400,["Slave1",RxData];
if RxData<>"T" then Loop;
Serin Rx,2400,receive your data here.
end routine.

I am at work, so I can't write the "exact code" but this can give you a idea how to start it. I believe you only have to put the correct format and be running.

If you notice, this was made for *many* slaves.

Dwayne

Jcee324
- 11th November 2004, 20:08
Dwayne, thanks for the code.

But I seen now that I must have misunderstood you. My program must have two masters. Both chips must be "listening" and be able to transmit as well as receive.

Thanks again for all help!
\Jonas