Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

USART Communication between two PIC Mucrocontrollers

Status
Not open for further replies.

jitun2

Member
I am developing some sort of multi controller device. It has two PIC microcontrollers (PIC18F4550 and PIC18F4680) can i use the USART for communication between the chips i.e. Can I just connect the RX of one chip to the TX of the other chip to do this? And can I use the serial data receive interrupt to read the data? At what maximum baud rate can i transfer the data? (The two microcontrollers just few centimeters apart as they are on the same board)
 
Yes, Yes, and consult the datasheet. You do have the respective datasheets: don't you?
 
ya i have the datasheets. Actually it runs fine in the simulation but i asked the question because i wanted to be sure.
 
In short? yes! You might want to add series resistors to both the lines (Tx->Rx, and Rx-> Tx) just incase something goes wrong. Something like 1-10k sohuld be fine.

You can of course use the data recieve interupt to 'read' the data. In fact, its probably the best way of doing it rather than polling the 'data recieved' flag.

The maximum baud depends on the oscillators in the PIC's. If they are only a few centimeters apart, I woudn't have thought you'd get much in the way of noise/signal degredation. Look at the datasheets and find the 'maximum' baud rate for the crystal osc's you're using. It'll probably be up in the MB/s range. If you wish to go even faster, PIC's USARTs have a sync mode, whereby a master produces a clock to go with the data, much more stable at high datarates, and can approach 2.5MB/s. Although as I said, one has to be a master and one has to be a slave (only the master provides the clock).

For async mode (normal USART operation) I would pick a baud that is perfectly accurate with your clocks. No point in configuring it for 19200 if you're oscillator would give the baud rate generator a % error. Check out the datasheet for the PICs and the BRG.

Alternatively you can use the SPI (MSSP) module to transfer bytes between the micro's at very high speed. If the PIC's are on the same board, and a few CM apart, then a good 5Mhz wouldn't be too tricky. Again with SPI, one has to be the master and one the slave, so only one provides the clock. On a side note SPI is a data exchange protocol...that is...when the master sends a byte to the slave, at the same time data is 'taken' from the slave.

Blueteeth
 
lol, bloody typical, I go off on one...and papabravo just does the short version ;)
 
Take a look at Application Note AN774 on the Microchip website.

It has working code examples of 4 or 5 communications usart methods, including the Interrupt driven Tx / Rx and polled / wait examples that can be downloaded in the .zip file and 'run' with little or no changes, it looks like it may be exactly what you want.

The App note covers the PIC16 / PIC17 and the PIC18 family as well.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top