PDA

View Full Version : Communication PIC to PIC?



droptail
- 13th January 2006, 21:57
How do I transfer a value (variable) from one PIC to another? Say w2=25 for example. I now use the SERout command to output an LCD display. Would this be the method, SEROUT and SERIN? How to set this imported value into the recieving PIC variable using PICBasic?

Thanks,

mister_e
- 14th January 2006, 00:31
Master:
SEROUT SerPin,Baud,[YourVar]

Slave:
SERIN SerPin,Baud,[YourVar]

---- OR ----

Master:
SEROUT SerPin,Baud,[#YourVar]

Slave:
SERIN SerPin,Baud,[#YourVar]

---- OR ----

Master:
SEROUT2 SerPin,Baud,[DEC YourVar]

Slave:
SERIN2 SerPin,Baud,[DEC YourVar]

---- OR ----
.
.
.
.

---- OR -----
.
.
.
.

droptail
- 14th January 2006, 04:23
Thanks Steve, I'll give her a try.

Rhatidbwoy
- 15th January 2006, 02:36
what do you do if you have 39 things to send and you do not want to eat up all that space with serin commands.

mister_e
- 15th January 2006, 11:21
39 things to send or receive?

To send => you can even use internal EEPROM or use an array variable.

To receive = > With SERIN2, look for the STR modifier.

Rhatidbwoy
- 16th January 2006, 15:44
ok. I think that I have found a way to get this moving. The problem that I have is that I broke my 16f648a and do not have another. I will be waiting for a while. But between what I have I think that it will work.

I have the programs of my work if you want to look. ironing out the little details to trans u2 ver 7 and still working on trans u1 ver2.

Ah quick question. the attachment MATH is part of u1 ver2. I am getting error leaving me to understand that I don't understand the math behind what is happening within the chip. Since I am doing multiplication and division my information is base 32 rather than 16? Is that what I am to understand?

peterdeco1
- 16th January 2006, 18:10
Very crude but it works. A while back I had to send 1 of 8 numbers to a slave PIC. I used SOUND command on master & COUNT command on slave. First number was near 100HZ, 2 was 200HZ, etc. Worked perfectly. Count command was limited to 100ms and allowed fast response. Count command needs a "window" like IF PULSESRECEIVED > 8 and < 12 THEN LET X = 0. Hope this helps.

mister_e
- 16th January 2006, 19:05
for your math you can't use float directly like that.

0.5 * x ===> still the same if you divide by 2

If x=1.5 ===> you should multiply by 10 then read IF x=15 depending of the previous math...

Well you should think integer than float.

droptail
- 17th January 2006, 01:02
Master:
SEROUT SerPin,Baud,[YourVar]

Slave:
SERIN SerPin,Baud,[YourVar]

---- OR ----

Master:
SEROUT SerPin,Baud,[#YourVar]

Slave:
SERIN SerPin,Baud,[#YourVar]

---- OR ----

Master:
SEROUT2 SerPin,Baud,[DEC YourVar]

Slave:
SERIN2 SerPin,Baud,[DEC YourVar]

.

SerOut B.6,N2400,[w2]

SerOut B.6,N2400,[#w2]

Referrrencing my above example, both get "bad expression" errors when compiling, whats wrong?

mister_e
- 17th January 2006, 01:48
What about


SerOut PORTB.6,N2400,[w2]

SerOut PORTB.6,N2400,[#w2]

droptail
- 17th January 2006, 03:15
Sho Nuff! Thanks Steve.

droptail
- 26th January 2006, 20:03
After being unsuccessful in transferrring the data from master to server, I now realize there must be some timing issues involved. How to time the transfer, or have slave wait until a successful serin has been made?

mister_e
- 27th January 2006, 03:57
use timeout of SERIN2 or DEBUGIN... PBP manual.

Rhatidbwoy
- 30th January 2006, 22:45
ok I have got the pics that I have been waiting for. I have tried one crued method mentions earlier in the this thread. If I had to set up one pic to wait for the command how would I go about that. That is of course using the SEROUT and SERIN command.

This is were it starts to get hairy.

BobK
- 31st January 2006, 01:27
Hello Rhatidbwoy,

I have a Master board with 20 slaves connected to it. Actually its 20 masters with 1 slave. The 1 board receives data from the various boards to be displayed and printed out on a POS printer. I have a BUSY line that is normally high. When any board has data to send to the display board it takes the busy line to ground for the duration of the transmission. The display board also takes the busy line to ground and holds it there until someone acknowledges the receipt of the alarm message then it releases then busy line so another message can come in. I'm using SERIN2/SEROUT2 on 16F877A's and my display board has an 18F452. The system has been working great. I also have a remote setup that is smaller with 16F872's in the 20 boards and a 16F877A in the display board. It really took a while to get the serial data stuff working reliably but a gentleman by the name of Steven Collins set me in the right direction. I also got some assistance from MElabs.

Main loop monitors several points including:
If BUSY = 0 then GOTO Getdata

Getdata:
PAUSE 5
SERIN2 serpin,36081,300,Main,[Wait ("A"),dec3 B7]

Upon receipt of the 3 character variable B7, the program now goes thru 320 lines of lookup to find a match thengoes to the display and printing routines.
The 300ms wait before going back the Main is because I put a response delay of 10 ms on each card so the each card waits 10ms more than the previous card so the last card (#20) will wait 190ms before sending its data. It's simple but effective!

The project also time stamps the printout, only sounds alarms between 8am and 4:30p Monday thru Friday but always prints. It also prints when the alarm returns to normal. The printer routines use DEBUGOUT.

Hope some of this helps you.

BobK

Rhatidbwoy
- 31st January 2006, 23:12
can not lie. It is confusing as heck. lol. I will have to read and reread to make sense out of it. It is an idea that is trued that was put together to make work. Instead of 20 different input (19 if 1 is to recieve all of this) I have 2. A master and slave which are both important for what I would like for them to do. I will have to try something.


You think it would work if I put the reciever into a continuous loop to recieve. When it finishes its recieving phase could I then AND certain portion of data and if it equals itself then move to the rest of the program. In the sense I have 4 parts. check part 1 AND 2, see if that is equal to the recieve value, part 3, then continue to part 4? Just throwing out ideas.

Rhatidbwoy
- 3rd February 2006, 02:23
SERIN2 serpin,36081,300,Main,[Wait ("A"),dec3 B7]

could the line above be explain in a little more detail. I follow to what you are to do, but I just do not understand it. I am trying something on my end with SERIN and SEROUT, but I think that I might have to switch to this SERIN2 and SEROUT2. Might make life easier. Who know.

BobK
- 3rd February 2006, 02:50
Hi Rhatidbwoy,

SERIN2 is fully explained on page 132 of the PBP manual. Serpin is the alias I have assigned to PortA.4 which is where the data will be received. 36081 is the mode of communications I am using derived from the Appendix A on page 201. 300 stands for 300ms which is the timeout for a signal to be received. If no data is received within the 300ms then GOTO Main. Wait ("A") tells the system to wait until the character "A" comes in. This is known as a qualifier. The dec3 tells SERIN2 to convert the decimal value in ASCII and store the value in variable B7.

I truely am not an expert like some of the other people on this forum and I am sure that they can give a more thorough explaination, but what I learned here comes from the manual and trying different things.

BobK

Rhatidbwoy
- 4th February 2006, 22:09
ok that is great help. The method that I am coming across to use is the HSER--- command.. The USART on hte device. I think that will clarify more to what I need to do, but still the problem with transmitting. I found info about that and it helps more than were I stand.

Rhatidbwoy
- 5th February 2006, 20:16
Another Quick one. I am trying to get HSERIN and HSEROUT to work. have you done anything with them. I have attached portion of my prog. does this even look right as far as direction wise.