View previous topic :: View next topic |
Author |
Message |
hayee
Joined: 05 Sep 2007 Posts: 252
|
two pics using RS232 |
Posted: Mon Feb 23, 2009 1:08 am |
|
|
Hi,
I want to send data from 1st pic16f877a to 2nd pic16f877a using RS232.
I am transmitting data from 1st pic but the data is not correctly receive by the 2nd pic.
In my program i am simply sending a value and on the receiver side it outputs on "port d" according to value sent by 1st pic.
code for transmitter side
Code: | void main()
{
int8 a;
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
while(1)
{
a=1;
if(input(PIN_B7))
{
output_high(PIN_D0);
printf("%d",a);
}
else
{
output_low(PIN_D0);
}
}
} |
code on receiver side
Code: | void main()
{
int8 x;
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
// TODO: USER CODE!!
while(1)
{
x=getc();
output_d(x);
}
} |
But i am getting wrong data on the receiver side. |
|
|
Ttelmah Guest
|
|
Posted: Mon Feb 23, 2009 3:13 am |
|
|
You need to post some other things:
1) The clock statements.
2) The #USE RS232 statements.
3) How the connections are made, and how long they are.
4) What the actual clock 'source' is on both PICs, and the fuses you are using with these.
Best Wishes |
|
|
hayee
Joined: 05 Sep 2007 Posts: 252
|
|
Posted: Mon Feb 23, 2009 3:25 am |
|
|
fuses settings on transmitter side
Code: | #include <16F877A.h>
#device adc=8
#FUSES NOWDT
#FUSES HS
#FUSES PUT
#FUSES PROTECT
#FUSES NOBROWNOUT
#FUSES NOLVP
#FUSES NOCPD
#FUSES NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) |
fuses settings on reciver side
Code: | #include <16F877A.h>
#device adc=8
#FUSES NOWDT
#FUSES HS
#FUSES PUT
#FUSES PROTECT
#FUSES NOBROWNOUT
#FUSES NOLVP
#FUSES NOCPD
#FUSES NOWRT
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) |
Also i have connected Tx of 1st PIC with Rx of 2nd PIC and Rx of 1st PIC with Tx of 2nd PIC.
Length is not a matter because both PIC are on same board.there supply are common. |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Tue Feb 24, 2009 8:57 am |
|
|
Can you give us some examples of what is sent and what is received? Seeing which bits are flipped or lost can tell us what is going wrong.
Also what is the clock source for the two PICs? _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
hayee
Joined: 05 Sep 2007 Posts: 252
|
|
Posted: Wed Feb 25, 2009 12:14 am |
|
|
Suppose I send
Code: | a=2;
printf("%d",a); |
It should send "2" to the receiver PIC.
On the receiver side
Code: | x=getc();
output_d(x); |
But on the receiver PIC I am getting data on port like "00110010".
then on receiver's port D I am getting "00110101".
But I resolve the problem by using putc().
now if a=2;
Then on the receiver's port D I am getting "00000010".
if a=15
Then on the receiver side I am getting "00001111".
But if you know how to send data using printf then tell me.
I have already mentioned that the clock source for both PIC are 20MHz. |
|
|
|