Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Pic to Pic communication

Status
Not open for further replies.

Ianb007

Junior Member level 1
Junior Member level 1
Joined
Feb 17, 2010
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,429
Hi. I need to send 5 bits of data from one 18f4431 pic to another 18f4431. I have looked all over just for a simple example c code, but battle to find anything simple and usefull which i could program onto the chip and test the basics first. Can anyone help? (Something like making a led blink connected to pic 2 from data obtained from pic 1. I want only one connection/line between the 2 pics besides the Vdd and Vss. I am using PICKit2 and C18 compiler.
 

Your could USART from both pics. How far both PICs are? If they are on the same board just connect the sender's TX to receiver's RX and you got it working. About the code take a look at MPLAB-C18-Libraries pdf. You can find it on the doc folder inside C18 Folder (MCC18). It is explained all fnctions to work with USART.

Cya
 

    Ianb007

    Points: 2
    Helpful Answer Positive Rating
just connect one pin from one mcu to another pin from another mcu, and program it accordingly.
 

I'm not very knowledgable about PICs but isnt there a
one line communication protocol for them (I seem
to remember reading about a temperature meter that used one)
Maybe that could help.

jack
 

one-wire is just one of many possible ways of doing it.
 
its about 3m. Will 3 or 10m make a huge difference? I will have a look at the library files. I just need something simple to copy and paste to program to the chips and then test-and later on i will add and modify everything. Thanks so far
 

Yea it will make a big difference. WIth that distance i dont think will be suitable to work with some syncronous comunication as SPI. What is transmission rate you are going to need? If it is very very very very slow i dont think you going to need any tranceiver. But if you need speed i would recomend you using 2 RS-485 tranceiver for that distance.
 

Thanks for the replies. What I need to do, to make it more clear: I need to control the lights of a trailer (for semi-truck) by using 1 (preferable) or 2 wires instead of the 7 used currently between the truck and trailer connecting plugs. So the distance could be reduce dto 2/3 meters if it makes such a big difference. I have my basic circuits built, but I am now busy with the pic-to-pic communication.
 

UART should be ur choice and first you have to make a test circuit which u can test it via hyperterminal...

PIC(TX)--->MAX232--->com port(PC)--->hyperterminal
 

can anyone give me a link or simple c code which i can program straight to the 2 pic's, one receiving a byte/string and the other sending the byte/string. I have found examples for the sending of something but i need the receiving part. (Using USART) As far as I see, the MC18 library only has AVR examples. This would be very help full for me if thats possible. I would just like to get that right/working and then I can carry on. Thanks.
 

Another question. How are you powering both PICs? Becouse at a wired comunication you must have the same reference at Transmitter and Receiver. If you dont have it already you must use a wire for that. My recomendation would be use RS485. You buy 2 MAX485 tranceivers (you can find them in DIP package and they are very cheap). You make a half-duplex comunication with it. Them you use a RJ-45 jack at each board (not the one with magnet, just the simple one). And a Ethernet cable. You going to have a real reliable comunication. You going to have total of 8 wires ( i know you wanted to use just 1) but inside the same cable. Yo could use 2 wires for the diferencial RS-485 comunication and the other wires for powering purposes if you need it. With taht configuration you can have very long distances if you use slow baud rates (up to 1KM!!). With that hardware configuration the comunication would be a simple asynchronous using UARTS from both PICs. Its very simple cheap and reliable. Let me know if you have any doubts or that is not suitable for you.

Cya
 

one wire is possible check Microchip for more details, 1 wire is normally used in automobiles.
 

If you need to control seven signals from one, and they don't need to change very fast, I would suggest using something similar to the coding method used by radio control servos. The communication line idles high for a minimum of something like 10ms between frames. Then for each object to be controlled, the communication line goes low for a duration proportional to the control setting. I think these pulses are something on the order of 100-900us, starting at 1ms intervals. Simple, robust, extensible, and it allows for analog as well as digital parameters (if you use the right timing parameters, you could add RC servos easily if you want mechanical control). Since the data rates aren't terribly high, I'd suggest using an opto-isolator. The communications wires should be connected through resistors to the IRled on the receiver board and nothing else.
 

    Ianb007

    Points: 2
    Helpful Answer Positive Rating
can anyone give me a link or simple c code ..

you really should learn to write your own code, either fully independently or by modifying others' code.

what you are trying to do is so simple, in my view, that providing you with a piece of code would have been an insult to you.
 

Can anyone tell me why this code does not show an ouput at the specified port of the receiver when a varying on/off input is present at the sender port where USART is written from???

Here is the code:
Sender:

#include <p18F4431.h>
#include <delays.h>
#include <usart.h>


void main()
{
TRISC = 0x00;
OSCCON = 0xf0;

OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF &
USART_ASYNCH_MODE & USART_EIGHT_BIT &
USART_CONT_RX & USART_BRGH_LOW, 12); //baud rate 9600 1.36% error

while(BusyUSART()) ;
WriteUSART(PORTB);


while(1); // *** loop forever
}







And receiver:

#include <p18F4431.h>
#include <delays.h>
#include <usart.h>


void main()
{

unsigned char c;
TRISC = 0xff;
OSCCON = 0xf0;

OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF
& USART_ASYNCH_MODE & USART_EIGHT_BIT &
USART_CONT_RX & USART_BRGH_LOW, 12);

while (!DataRdyUSART())
c = ReadUSART();

PORTB = c; //show result with LEDs

while(1);
//closeUSART();
}

TX sender is connected to Rx receiver
 

why this code does not show an ouput at the specified port of the receiver

because you wrote the code so that the mcu doesn't do what you want it to do.
 

Try modifying your code for transmitter like that:
Code:
while(1){
WriteUSART(0xB6); //some random value
}

And for reciever:
Code:
while(1){
while (!DataRdyUSART()) 
c = ReadUSART(); 

PORTB = c;
}

Because the way you have it right now transmitter send value once and reciever might miss it.

Now one is constantly sending and the other is constantly waiting for data.
 

    Ianb007

    Points: 2
    Helpful Answer Positive Rating
Thanks for the help, and I know that I have to learn to program properly myself, but I want to just get the basics going since I have to later do error checking etc too and I don't have a whole lot of time to spend on this.

ok. I changed my code and if I connect an oscilloscope to the TX-RX line i can see that whenever I switch a pin on Port B of pic1 (sender), the signal on the RX/TX line changes. However, pic2 does not give a 5V on any of the ports when I switch on pic1. Is it not supposed to work the way I programmed it?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top