View previous topic :: View next topic |
Author |
Message |
bright
Joined: 24 Apr 2011 Posts: 14
|
Communicating two pic microcontrollers using UART |
Posted: Wed May 04, 2011 2:44 pm |
|
|
I am trying to communicate two pic16f690 microcontrollers using UART. I have given my test code for both the receiver and transmitter. For testing purposes in the receive side I connected LEDs to all the pins of PORTC but no LED turns on when I run this code.
RECEIVER:
Code: |
#include<16f690.h>
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B5, bits = 8)
int8 c;
void main(void)
{
c = getc();
delay_ms(1000);
output_c( c );
while(1);
}
|
TRANSMITTER:
Code: |
#include <16F690.H>
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_B7, rcv=PIN_B5, bits = 8)
void main(void)
{
putc(0xFF);
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Wed May 04, 2011 4:28 pm |
|
|
some items..
Your trasmitter code sends 0xFF once then goes to sleep..
You need to creat a continuous loop of sending a byte, then waiting say 1 second, and repeat forever.
I would suggest incrementing the data from 0x00 to 0xff to verify that it really works.Sending the same data is not a good test.
Also you should add 'errors' to the use Rs232(...) preprocessor directive.
Be sure that both xmt,rcv and gnds are connected properly
Also use appropriate current limiting resistors with the LEDs! |
|
|
ALPL
Joined: 29 Mar 2009 Posts: 30
|
|
Posted: Thu May 05, 2011 12:00 pm |
|
|
Hi , the code cannot work at all. On the receiver side I suggest to use an ISR to catch any incoming data and interpret them in the main function in the while(1)-loop.
As already mentioned: on the sender side send continuously a byte eg every second. |
|
|
|