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 support@ccsinfo.com

pic to pic communication using rs232

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



Joined: 28 Feb 2011
Posts: 2

View user's profile Send private message

pic to pic communication using rs232
PostPosted: Mon Feb 28, 2011 10:54 pm     Reply with quote

Hi guys,
I am new to this forum. Could you all please give some opinion about my codes. I don't know whether it is correct or not. I want to transmit data from PIC 1 to PIC 2 using rf module. Then transmit the data to PC using rs232. I am using PIC18F4550. TX and RX(433MHz). Thank you.

Tx code:
Code:

#include <18F4550.h>
#use delay(clock=20000000)
#fuses INTRC_IO, NOWDT, NOPUT, NOBROWNOUT, MCLR, NOLVP, NOPROTECT

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS, STREAM=COM_B)
#define PIN_A0=COM_B

void main()
{
   while(1)
   {     
         getc(COM_B);
         delay_ms(20);
         putc('T');
         delay_ms(20);
     
         output_high(PIN_A1);
         delay_ms(100);
         output_low(PIN_A1);
         delay_ms(100);
   }
}


Rx code:
Code:

#include <18F4550.h>
#use delay(clock=20000000)
#fuses INTRC_IO, NOWDT, PUT, BROWNOUT, MCLR, NOLVP, NOPROTECT
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,parity=N,bits=8,ERRORS,STREAM=COM_A)

unsigned int8 data;
int1 flag=0;

#int_rda
void rd_isr(void)
{
   //disable_interrupts(INT_RDA);           // Disable Serial Recieve Interrupt
   //disable_interrupts(GLOBAL);            // Disable Global Interrupts

   data= fgetc(COM_A);

   if(data=='T')
   {
      flag=1;
   }

   //enable_interrupts(GLOBAL);
   //enable_interrupts(INT_RDA); 
}

void main()
{
   enable_interrupts(global);
   enable_interrupts(int_rda);
   
   while(true)
   {
      if(flag==1)
      {
         output_high(PIN_B6);
         delay_ms(100);
         output_low(PIN_B6);
         delay_ms(100);
         
         flag=0;
      }
      else
      {
         delay_ms(100);
         
         delay_ms(20);
         fputc(0x55,COM_A);
         fputc(0x00,COM_A);
         fputc(0xFF,COM_A);
         delay_us(80);
         fputc('T',COM_A);
         delay_ms(20);
         
         delay_ms(100);
      }
     
         output_high(PIN_B2);
         delay_ms(100);
         output_low(PIN_B2);
         delay_ms(100);
   }
}
atai21



Joined: 30 Dec 2010
Posts: 31

View user's profile Send private message

PostPosted: Tue Mar 01, 2011 1:02 am     Reply with quote

Can you show me the circuit?
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Mar 01, 2011 7:54 pm     Reply with quote

Could you give us a description of what you expect the code to do? Also can you tell us what type of RF circuits you are using? Note that RF links are famous for giving lots of garbage characters, especially nulls, along with the desired data.
_________________
The search for better is endless. Instead simply find very good and get the job done.
temtronic



Joined: 01 Jul 2010
Posts: 9182
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Mar 01, 2011 8:21 pm     Reply with quote

Break up the project into smaller projects.

Forget about the RF sections and just hardwire the two PICs and test your code that way. You'll save a LOT of time. Once you have them working properly then add the RF modules and see what happens.
At least then if it doesn't work, you know it's in the RF section and not the original code.
pari88



Joined: 28 Feb 2011
Posts: 2

View user's profile Send private message

PostPosted: Tue Mar 01, 2011 8:37 pm     Reply with quote

Quote:
Could you give us a description of what you expect the code to do? Also can you tell us what type of RF circuits you are using? Note that RF links are famous for giving lots of garbage characters, especially nulls, along with the desired data.


I want to transmit data from a sensor to PIC 1 then to PIC 2 then to PC through rs232. From PIC 1 to PIC 2, I used a transmitter and a receiver with 433MHz.

Quote:
Break up the project into smaller projects.

Forget about the RF sections and just hardwire the two PICs and test your code that way. You'll save a LOT of time. Once you have them working properly then add the RF modules and see what happens.
At least then if it doesn't work, you know it's in the RF section and not the original code.


Ok. I will take your advice.
altanonat



Joined: 07 Feb 2011
Posts: 21
Location: Turkey

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Thu Mar 03, 2011 3:35 am     Reply with quote

If you are using cheap 433 mhz rf modules, the baudrate you are using is very high. I am also doing a project like this using pic18f4550. I can only be successful by adjusting baudrate to 300 with 20 mhz crystal.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Thu Mar 03, 2011 6:42 am     Reply with quote

An issue to examine with PIC to PIC communications is whether you are going to be asynchronous or synchronous. An interrupt driven receive with a circular buffer is almost needed every time if reliable results are expected with asynchronous setups. It looks like this project is synchronous with a master sending "T" and the slave only transmitting when it receives it. This means the receiver can rely in the hardware buffer ( last char received) in the PIC uart to capture the "T". The receiver must process this and let the transmitter know it has a one char buffer available again. It is never a good idea to put delays or printf statements in a RDA ISR ( this code avoids this no no). The RF will most likely mess up chars. The transmitter needs to know if the receiver got the char and the receiver needs to process a messed up char and request a retransmission. The receiver and the transmitter may need to exchange greetings on startup the 3 way hand shake might be used... Hello ...hello back ... thanks for the hello back. It helps to plan this before beginning coding. Test the simplest possible transfer
then proceed to further coding. Don't try to swallow the whale eat a byte ( pun for bite) at a time.
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