Communication PIC to PIC?


Closed Thread
Results 1 to 20 of 20
  1. #1
    Join Date
    Nov 2004
    Location
    Calabasas, CA
    Posts
    84

    Default Communication PIC to PIC?

    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,
    James

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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 -----
    .
    .
    .
    .
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Nov 2004
    Location
    Calabasas, CA
    Posts
    84


    Did you find this post helpful? Yes | No

    Default

    Thanks Steve, I'll give her a try.
    James

  4. #4
    Rhatidbwoy's Avatar
    Rhatidbwoy Guest


    Did you find this post helpful? Yes | No

    Default

    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.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6
    Rhatidbwoy's Avatar
    Rhatidbwoy Guest


    Did you find this post helpful? Yes | No

    Default

    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?
    Attached Files Attached Files

  7. #7


    Did you find this post helpful? Yes | No

    Default

    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.

  8. #8
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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.
    Last edited by mister_e; - 16th January 2006 at 19:09.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  9. #9
    Join Date
    Nov 2004
    Location
    Calabasas, CA
    Posts
    84


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    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?
    James

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    What about
    Code:
    SerOut PORTB.6,N2400,[w2] 
    
    SerOut PORTB.6,N2400,[#w2]
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  11. #11
    Join Date
    Nov 2004
    Location
    Calabasas, CA
    Posts
    84


    Did you find this post helpful? Yes | No

    Default

    Sho Nuff! Thanks Steve.
    James

  12. #12
    Join Date
    Nov 2004
    Location
    Calabasas, CA
    Posts
    84


    Did you find this post helpful? Yes | No

    Default sync data transfer?

    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?
    James

  13. #13
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    use timeout of SERIN2 or DEBUGIN... PBP manual.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  14. #14
    Rhatidbwoy's Avatar
    Rhatidbwoy Guest


    Did you find this post helpful? Yes | No

    Default

    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.
    Last edited by Rhatidbwoy; - 30th January 2006 at 22:47.

  15. #15
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    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

  16. #16
    Rhatidbwoy's Avatar
    Rhatidbwoy Guest


    Did you find this post helpful? Yes | No

    Default

    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.

  17. #17
    Rhatidbwoy's Avatar
    Rhatidbwoy Guest


    Did you find this post helpful? Yes | No

    Default

    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.

  18. #18
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    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

  19. #19
    Rhatidbwoy's Avatar
    Rhatidbwoy Guest


    Did you find this post helpful? Yes | No

    Default

    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.

  20. #20
    Rhatidbwoy's Avatar
    Rhatidbwoy Guest


    Did you find this post helpful? Yes | No

    Default

    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.
    Attached Files Attached Files

Similar Threads

  1. 2 PIC, serial communication
    By lightgreen in forum Serial
    Replies: 6
    Last Post: - 21st November 2009, 15:20
  2. PIC to PIC "wired" serial one-way communication - SERIN2/SEROUT2
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th April 2008, 20:02
  3. PIC 2 PIC communication
    By Mario in forum Forum Requests
    Replies: 16
    Last Post: - 28th April 2006, 01:56
  4. Serial communication PIC to PIC help.
    By Rubicon in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th January 2005, 15:45
  5. Pic to Pic communication?
    By Rob Martin in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th April 2004, 19:41

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts