CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

two pics using RS232

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

two pics using RS232
PostPosted: Mon Feb 23, 2009 1:08 am     Reply with quote

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







PostPosted: Mon Feb 23, 2009 3:13 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 23, 2009 3:25 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Feb 24, 2009 8:57 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Feb 25, 2009 12:14 am     Reply with quote

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".
Code:
if a=15

then on receiver's port D I am getting "00110101".

But I resolve the problem by using putc().

now if a=2;
Code:

a=2;
putc(a);

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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