CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

how to get 2 PIC 18F4431 to talk

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
RyanJ



Joined: 19 Jul 2007
Posts: 6
Location: New -Brunswick

View user's profile Send private message Send e-mail MSN Messenger

how to get 2 PIC 18F4431 to talk
PostPosted: Fri Jul 20, 2007 7:58 am     Reply with quote

Hi,
Im trying to get 2 PIC18F4431 to talk to each other, im new to this so im wondering if it is easier in hardware or software mode! 1 PIC as the slave and one as the master. Does anyone have code to make them talk!
thanks
Ryan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 20, 2007 12:08 pm     Reply with quote

Using the i2c bus:
CCS i2c Slave example:
c:\Program Files\picc\Examples\Ex_Slave.c

Test code for an i2c Master to talk to the PIC running Ex_Slave.c code:
http://www.ccsinfo.com/forum/viewtopic.php?t=28097&start=9


Using the SPI bus:
CCS spi slave example:
c:\Program Files\picc\Examples\Ex_spi_slave.c

Other sample code:
http://www.ccsinfo.com/forum/viewtopic.php?t=26888
Bill Boucher



Joined: 04 Feb 2005
Posts: 34
Location: Chatham,ON,CA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Jul 20, 2007 12:19 pm     Reply with quote

By "Talk", you could use
-parallel data bytes passed between ports
-asynchronous serial rs232-style bytes between I/O pins, either on 1 wire, 2 or even more
-SPI synchronous transfers
-something you invent

and any of these could be done in software or hardware peripherals and using interrupts or not.

That said, you have a world of options available. If this is new to you, I suggest that you start very simply such as by using #USE RS232() and 2 pins on each PIC connected to each other (thru 220 ohm resistors just in case you make a mistake, don't wanna blow pins) and try sending just a couple of bytes back and forth and get that working first. Later you can learn about interrupts and how to make transmit and receive buffers and stuff like that. For now, keep it simple.

With software or hardware serial, so long as there's no interrupts involved, you can create pretty simple exchanges. Read the CCS manual for examples on how to implement simple RS232 transmit (putc,fputc) and receive (getc,fgetc) functions and how to use kbhit() to see if data is available before calling getc() and how to use the "stream" identifier to refer to a specific RS232 channel if you have more than one defined.

After a #use_rs232() is defined, a PIC wanting to send data could do so as simply as:
Code:

     putc(my_data);

or
Code:

     putc('A');

or
Code:

     putc("Hello World");

The receiving PIC might do this:
Code:

     my_data = getc();

or
Code:

     if (kbhit())
          {
          my_data = getc(); //receive 1 byte and put it into my_data;
          }

If you want to receive more bytes, you'd have to call a getc() for each one. Say there where supposed to be 4 bytes...
Code:

     int8 my_data[4];
     int8 idx;
     for(idx=0;idx<4;++idx)
         {
         my_data[idx] = getc();
         }


There are limitations to the above, but like I said, it's simple stuff meant to demonstrate the basic functionality. There is no limit to how much more complicated communications can get, such as implementing interrupt-driven reception and transmission, ram buffers, checksums or 16-bit CRC checksums, or ascii-encoding and decoding, structured data packets, automatic timeouts if data doesn't arrive as expected, and so on.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group