PDA

View Full Version : Pic To Pic Serial Communication?



ngeronikolos
- 2nd February 2005, 14:17
HELLO BOYS!!
I AM NIKOS FROM GREECE!!!

I AM A NEW USER OF THE PICBASIC PRO LANGUAGE SO I DO NOT KNOW A LOT ABOUT IT.I USED TO PROGRAM PIC WITH ASSEMPLY.I HAVE READ THE PICBASIC PRO COMPILER BOOK.
WHAT I AM LOOKING FOR IS A CONSTRUCTION WITH A MASTER PIC 16F84A AND 16 OTHER SLAVES PICS.THE MASTER SHOULD SEND FIRST AN ADDRESS(SERIALLY).ALL SLAVES PIC SEARCH FOR THE RIGHT ADDRESS .ONLY ONE HAS THE RIGHT ADDRESS.AFTER THAT THE MASTER STARTS TO SEND THE INFORMATION TO THE CORECT PIC.


PLEASE I NEED YOUR HELP!!!!!

Dwayne
- 2nd February 2005, 14:44
In the FAQ, there is a section on serial communication with pics.

Step 1 is getting communication between 2 chips.
Step 2 is easy too.
With communication established, you can use SERin and SERout to control which chips receive what. The "Code" string can be 2 charactors chosen specifically for a certain chip. and the data following the code string is your info being sent to the chip.

So lets start with Step 1 ok? Have you got communication between two chips? Where one will send data, and the other will put the data on a LCD? If you do not have this communication between two chips, you are wasting your time.

Dwayne

ngeronikolos
- 2nd February 2005, 14:57
Hello my friend Dwayne,

NO,I DO NOT HAVE COMMUNICATION BETWEEN THE TWO PICS. A AM LOOKING THE WAY FOR STEP-1&2!! I AM GOING TO USE PIC 16F84A!!I DO NOT THING THAT IS HARD BUT IT IS TOO HARD FOR ME WHO READ THE MANUAL FOR PICBASIC PRO TWO DAYS AGO!!
I KNOW ONLY ASSEMPLY.

I AM WAITING YOUR REPLY

Dwayne
- 2nd February 2005, 15:28
Hello Ngeron,

Ok Ngeron, First go to the following link, and get a communication link going.

http://www.picbasic.co.uk/forum/showthread.php?s=&threadid=579


The above link is step 1. Attempting step 2 is worthless, unless you have step 1 complete and operating.

Dwayne

ngeronikolos
- 3rd February 2005, 13:16
Hello,

I read the above link,i make the program as it says,but i have a problem.The pbp find a problem in my program.

This is:
'SERout MASTER

B0 = %00000001
loop: Serout POTB.0,T2400,[B0] <--- it finds error here
Pause 100
goto loop


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

' SERin slave
DataRec Var byte
loop: Serin A0,T2400,DataRec <--- it finds error here
Serout B0,T2400,DataRec <--- it findserror here
goto loop



Where is the fult?
I want to say also that i use the pbp demo version.

mister_e
- 3rd February 2005, 13:50
Can be because you don't have do some definessssss



This is:
'SERout MASTER
include "modedefs.bas"
TRISB.0=0
B0 var byte

B0 = %00000001

loop:
Serout PORTB.0,T2400,[B0]
Pause 100
goto loop


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

' SERin slave
include "modedefs.bas"

TRISB.1=1
A0 var PORTB.1

TRISB.0=0
B0 var PORTB.0

DataRec Var byte

loop:
Serin A0,T2400,DataRec
Serout B0,T2400,DataRec

goto loop


i don't like to say that but, look into your PBP book in the SERIN/SEROUT section... and do a search within this forum, and on the Melabs website in the code example section.

ngeronikolos
- 4th February 2005, 07:31
I can not use <<include>> in my programm. I use pbp demo and I do not have this permittion!!!


Can someone help me with the eerors i find?




This is:
'SERout MASTER

B0 = %00000001
loop: Serout POTB.0,T2400,[B0] <--- it finds error here
Pause 100
goto loop


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

' SERin slave
DataRec Var byte
loop: Serin A0,T2400,DataRec <--- it finds error here
Serout B0,T2400,DataRec <--- it findserror here
goto loop

ngeronikolos
- 4th February 2005, 07:33
I mean I can not USE the <<include>>

badrad
- 4th February 2005, 08:13
did you include the modedefs.bas file? you need that for your serial communications.

include "modedefs.bas"

ngeronikolos
- 4th February 2005, 12:26
WHERE IS THE ERROR?THE PBP DEMO VERSION SAID THAT I HAVE A DAD EXPRESION.

HELP MEEEEEEEEEEEEEE





TRISB.0=0
B0 var byte
B0 = %00000001

loop:
Serout PORTB.0,T2400,[B0] <--DAD EXPRESION
Pause 100
goto loop

mister_e
- 4th February 2005, 15:18
Serout PORTB.0,0,[B0]

what about now ?!?

ngeronikolos
- 4th February 2005, 15:34
hello steve


what is mean the second 0.this or not the baud rate?

mister_e
- 4th February 2005, 15:43
If you don't include "modedefs.bas" the second "0" will refer to T2400 bauds.

Since you're using the demo, i'm not sure if they include this "modedefs.bas" file. BTW i never place this include, i use specific VAR or i let it like that and i place comment at the right edge of the line.




TRISB.0=0 ' set PORTB.0 as output
SerPin var PORTB.0 'alias to PORTB.0
T2400 con 0 ' Alias to 2400 baudrate mode true
' for SEROUT

start:
serout serpin,t2400,["hello"] ' send hello @2400 bauds
pause 1000 ' wait 1 second
goto start

ngeronikolos
- 4th February 2005, 16:01
---------------master pic------------------
TRISB.0=0

start:
serout Potrb.0,0,[1]
pause 1000
goto start


-----------------slave pic---------------------
DataRec Var byte

loop:
Serin PortA.0,0,DataRec
Serout portB.0,0,[DataRec]

goto loop


do you think that is correct?do you thnik that slave pic will recognize the 1?

thnks for all

mister_e
- 4th February 2005, 16:11
Close to be good. The only thing you have to add to the slave PIC, for safety sake, is the TRIS setting.



TRISA.0=1 ' set PORTA.0 as input
TRISB.0=0 ' set PORTB.0 as output

DataRec Var byte

loop:
Serin PortA.0,0,DataRec
Serout portB.0,0,[DataRec]

goto loop


it can also work without the TRIS setting since SERIN/SEROUT are *suppose* to set TRIS direction... what is to add 2 line to be sure ?!?

In the Master PIC...


serout Potrb.0,0,[1]

typo error PORTB.0 ;)

So if you monitor it at the end you'll send the ASCII 1.

mister_e
- 4th February 2005, 16:17
just a add on to be sure. If you want to test a specific character, the slave can be something like this.




TRISA.0=1 ' set PORTA.0 as input
TRISB.0=0 ' set PORTB.0 as output

DataRec Var byte

loop:
Serin PortA.0,0,[1]
Serout portB.0,0,["I've receive 1.. yeah!!!"]

goto loop


OR




TRISA.0=1 ' set PORTA.0 as input
TRISB.0=0 ' set PORTB.0 as output

DataRec Var byte

loop:
Serin PortA.0,0,DataRec
if DataRec = 1 then
Serout portB.0,0,["I've receive 1.. yeah!!!"]
else
Serout portB.0,0,["Bad :-("]
endif
goto loop

ngeronikolos
- 4th February 2005, 16:49
Dear Dwayne,

I manage to make a simply conection between two pics!!!!
That ws the step1.

Please advise me with the step2.

many thanks

ngeronikolos
- 4th February 2005, 17:03
thank you Steve.


The only problem I face is with the PicBasic Pro Comiler.It is Demo Version.

Dwayne
- 4th February 2005, 18:00
Hello Nikilos,

N>>I manage to make a simply conection between two pics!!!!
That ws the step1.

Please advise me with the step2.<<

Ok, now that you have a simple verifyable connection using SERIN and SERout, lets expand on your SERin and SERout, and use another function of SERin and SERout.

USE YOUR WORKING PROGRAM that works for you. Steve has helped you remendously. When I talk to you, I will be talking in GENERALIZATION. I do not have a compiler here where I am at right now, so my programs are PSUEDO examples. Use the working example you got from Steve. He have you a couple of working examples, all varied just a little, but still worked.

******the following is PSUEDO**********
Serout PinNumber,Baudrate,["test"],"A";

Serin PinNumber,Baudrate,["test"], Variable
LCDout Variable.

Something like this: (this is very close to the example in the book.)

SERIN 1,N2400,[“test”],Variable
************************************




What this does, is read pin number "1", and until it receives the filter letters "test" (completely reads *all* the letters test), it will NOT put a character into Variable

So, if you want to send the word "Hello", your transmitter must send the following data:
testH
teste
testl
testl
test0

The 'test' will be ignored, and the letter following test will be placed in the "Variable".


With this information, The Master Chip can send any data to any slave chip, by sending the correct "test", or "Code" that corrisponds to the slave chip.

Slave Chip #1, could have SERIN 1,N2400,[“Slave1”],Variable
Slave Chip #2, could have SERIN 1,N2400,[“Slave2”],Variable
Slave Chip #3, could have SERIN 1,N2400,[“Slave3”],Variable

That way None of the other slaves will respond to any of the other slave chips, as the data is being sent back and forth to the master slave.

Step 2, is getting the receiver to respond and print only the character after the "filter characters". (In the above case SlaveX is the filter Character, and the letter following the filter characters is what you want to see).

Since you already have communication between the two chips with the Serin/Serout, you need to use the same command, and make sure you can use the "Filter"

Remember... 1 step at a time...You have communication, and you can verify it. This is also part of step 1...Changing the program (just a small bit) to enable "Filters" to work.




Dwayne

mister_e
- 5th February 2005, 00:59
I just make a new thread in the code example section.

click here (http://www.picbasic.co.uk/forum/showthread.php?s=&threadid=1192)