|
|
View previous topic :: View next topic |
Author |
Message |
sonicdeejay
Joined: 20 Dec 2005 Posts: 112
|
Setting up communication between 2 PIC uC |
Posted: Mon Feb 06, 2006 9:01 pm |
|
|
How can I set up communication between 2 PIC as pass variables values each other....
I need it as I am doing control project and 2 differnt program running simultanously and pass info to each other..
I gona use 2 uC (PIC18F2525) and hopefully it can support i2c(i need it?) function...
thx
sonic
|
|
|
sonicdeejay
Joined: 20 Dec 2005 Posts: 112
|
|
Posted: Fri Feb 10, 2006 9:01 pm |
|
|
any example guys???
help me out here...
thx
sonic |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 10, 2006 9:28 pm |
|
|
Quote: | How can I set up communication between 2 PIC as pass variables values each other.... |
For you, the easiest way would be to use the hardware serial port on
each PIC. If the PICs are very close to each other, then you don't need
MAX232-type drivers. Just connect Tx on one PIC to Rx on the other
PIC. Then use putc() to send data, and use getc() to receive data.
(or use EX_SISR.C and bgetc() ). |
|
|
sonicdeejay
Joined: 20 Dec 2005 Posts: 112
|
|
Posted: Fri Feb 10, 2006 10:52 pm |
|
|
ya..I can do that,they are very close each other,,I don't really need i2c right??
but i will also need to hook up RS232 connection to COM PORT...
for my proj...I have few PORT A and Port C pin avail....
Code: | #include <18F1320.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B4, ERRORS, stream=HW_UART)
#use rs232(baud=9600, xmit=PIN_B0, rcv=PIN_B2, stream=SOFT_UART)
void main(void)
{
char c;
setup_adc_ports(NO_ANALOGS);
fprintf(HW_UART, "Start\n\r"); // Send to hardware UART
c = fgetc(HW_UART); // Get char from hardware UART
fputc(c, SOFT_UART); // Transmit it with software UART
while(1); // Don't let PIC go to sleep
} |
Last edited by sonicdeejay on Sat Feb 11, 2006 9:13 pm; edited 2 times in total |
|
|
depp Guest
|
|
Posted: Sat Feb 11, 2006 3:15 am |
|
|
Quote: |
If the PICs are very close to each other, then you don't need
MAX232-type drivers
|
Do u mean that its the physical distance between the PICs that determine whether to have Level shifters in between. Dont we have to invert the levels, regardless of the distance? |
|
|
sonicdeejay
Joined: 20 Dec 2005 Posts: 112
|
|
Posted: Sat Feb 11, 2006 7:07 am |
|
|
PCM programmer,,,
Can I just use RS232 to communicate each other?
Don't I need some kinda of handshaking? |
|
|
Ttelmah Guest
|
|
Posted: Sat Feb 11, 2006 10:59 am |
|
|
On distance, yes.
You can send standard logic signals many inches, and in electrically 'clean' enviroments, many feet. However as the distance gets longer problems appear. Increased likelyhood of noise pickup, and danger of damage to the chips themselves if this gets really bad. So there is no "1m is OK, 2m is not" type answer, but as a general rule communication on the same board, or inside a shielded case, between boards that share the same ground, would be fine without transceivers.
RS232 transcievers, give higher signalling voltages, setup to give improved noise rejection, and protection agains spikes (depending on the chip selected), of several thousand volts. While this sounds high, the normal 'finger spike' from touching a pin after walking across a carpet, can easily be at this sort of level...
No, you don't have to invert. The standard TTL serial, is an inverted signal (-ve logic). This is done, because the RS232 transmitter chips, and receiver chips each normally contain an inverter, so the inverted TTL signal, is inverted by the driver, to make a positive logic signal sent over the wires. At the other end, the receiver inverts this again, to generate a -ve logic signal. Connecting directly, you remove both inverters, so a -ve logic signal leaves the chip, and is received by the second chip, which also expects a -ve logic signal.
Handshaking is entirely dependant on how you handle the serial. If you use an interrupt driven receive routine, with buffering, and the receiving chip is able always to decode a given message in less time than it takes another one to be sent, then no handshake is necessary. If however the receiving chip, has to go off, and do other things that takes longer than the number of characters that can be held either in the internal hardware buffering, or in a software buffer, then it becomes necessary to implement a handshake system. Remember that handshake can be a simple as an XON/XOFF code transmission, so no extra wires may be needed.
Best Wishes |
|
|
sonicdeejay
Joined: 20 Dec 2005 Posts: 112
|
|
Posted: Sat Feb 11, 2006 12:37 pm |
|
|
wow...encouraging,,,,, the 2 PIC will be placed side by side and connect in the following drawing....
as u can see..
PIC 1 will need 2 sets of RS 232 and PIC 2 will need 1 RS 232...
I have no problem making PIC 1 Port C6 and C7 talk to the PC via Max232....
Code: | use rs232(baud=9600, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8) // RS232 Configuration for COM Port Communication |
but...
I have no idea how can I configure... Port C0 and C1 to communicate between 2 PIC... |
|
|
Ttelmah Guest
|
|
Posted: Sat Feb 11, 2006 4:10 pm |
|
|
Keyword, _streams_. This allows you to have multiple serial ports, and select these by name. A search here on streams, or a look in the manual, should bet you started.
However caveat. A lot will depend on what you actually want to do with this link between the chips?. A software RS232, can only receive data, if the code is sitting waiting for it, or at low rates, if an interrupt is used to trigger the fetch. As such, linking two PICs like this, may be very hard to program...
If the chips you are using have the MSSP port, and you are not already using it for I2C or something else, consider using this instead. This is a high speed serial link designed to link chips in exactly this way. Even if this port, is already being used on one of the chips, then consider making this the 'master', and the other the 'slave' (assuming that such a designation is possible), and use software I2C on the master chip, and hardware I2C on the slave, which then allows the hardware buffering present in this pripheral to be used.
Best Wishes |
|
|
linhnc308
Joined: 16 Feb 2006 Posts: 9 Location: Viet Nam
|
|
Posted: Thu Feb 16, 2006 11:49 am |
|
|
How about I2C, when i connect two PIC via I2C.
Help me the code
mail: linhnc308@yahoo.com |
|
|
|
|
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
|