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

rs232 communication between two pic microcontroller

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



Joined: 24 May 2010
Posts: 10

View user's profile Send private message

rs232 communication between two pic microcontroller
PostPosted: Wed Jun 02, 2010 5:27 am     Reply with quote

Hi folks,

I want to make rf temperature with using rs232 communication. I've already tried some code pieces but I didn't succeed. Any idea or help would be more than welcome.

Btw, microcontroller model isn't important for me.

::::::::::::::::::::::::: Transceiver :::::::::::::::::::::::::::::::
Code:

// mikrodenetleyici baþlýk dosyasý
#include <18F4550.h>

// gerekli register ayarlarý
#FUSES   NOPROTECT, NOPUT, NOWDT, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NOMCLR, XT

// 10bitlik analog çýkýþ
#device  ADC=10

// saat çarpan hýzý 4mHZ
#use     delay(clock=4000000)

// Seri iletiþim(USART) için gerekli ayarlar. Bu bildirim ile seri çýkýþ birimi seri porta
// yönlendirilmiþtir.
// Bant hýzý 9.6kbps, verici pini C6, alýcý pini C7, pariti biti yok, 8bitlik iletiþim
#use     rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8)   

// B portunu LCD için tahsis et
#define USE_PORTB_LCD TRUE

#include <lcd.c>
#include "ds18b20.c"
#include "mpx4115.c"

#define T_BUFFER_SIZE 64
byte t_buffer[T_BUFFER_SIZE];
byte t_next_in = 0;
byte t_next_out = 0;


#int_tbe
void serial_isr() {

   if(t_next_in!=t_next_out)
   {
      putc(t_buffer[t_next_out]);
      t_next_out=(t_next_out+1) % T_BUFFER_SIZE;
   }
   else
      disable_interrupts(int_tbe);
}

void bputc(char c) {
   short restart;
   int ni;

   restart=t_next_in==t_next_out;
   t_buffer[t_next_in]=c;
   ni=(t_next_in+1) % T_BUFFER_SIZE;
   while(ni==t_next_out);
   t_next_in=ni;
   if(restart)
      enable_interrupts(int_tbe);
}

void main(void)
{
   float temperature, pressure;        // global deðiþkenlerin tanýmlanmasý
   
   setup_adc_ports(AN0);            // PortA'nýn 0.pinini analog olarak ayarla
   setup_adc(ADC_CLOCK_DIV_4);      //
   set_adc_channel(0); 
   
   
   enable_interrupts(GLOBAL);
   
   do
   {
      temperature = ds1820_read();  // ýsý deðerini sensörden oku
      pressure = mpx4115a_read();   // basýnç deðerini sensörden oku
     
      delay_ms(2000);
     
      printf(bputc,"%3.1fC\r\n",temperature);
   }
   while (TRUE)
         ;

}


::::::::::::::::::::::::: Receiver ::::::::::::::::::::::::::::
Code:

// mikrodenetleyici baþlýk dosyasý
#include <18F4550.h>

// gerekli register ayarlarý
#FUSES   NOPROTECT, NOPUT, NOWDT, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NOMCLR, XT

// 10bitlik analog çýkýþ
#device  ADC=10

// saat çarpan hýzý 4mHZ
#use     delay(clock=4000000)

// Seri iletiþim(USART) için gerekli ayarlar. Bu bildirim ile seri çýkýþ birimi seri porta
// yönlendirilmiþtir.
// Bant hýzý 9.6kbps, verici pini C6, alýcý pini C7, pariti biti yok, 8bitlik iletiþim
#use     rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, parity=N, bits=8)   

// B portunu LCD için tahsis et
#define USE_PORTB_LCD TRUE

#include <lcd.c>

//char  const msg_default[] = "Booting..";
//char str[20];
//char tmpStr[20];
//long strSize;
//int i;

#define BUFFER_SIZE 32
BYTE buffer[BUFFER_SIZE];
BYTE next_in = 0;
BYTE next_out = 0;


#int_rda
void serial_isr() {
   int t;

   buffer[next_in]=getc();
   t=next_in;
   next_in=(next_in+1) % BUFFER_SIZE;
   if(next_in==next_out)
     next_in=t;           // Buffer full !!
}

#define bkbhit (next_in!=next_out)

BYTE bgetc() {
   BYTE c;

   while(!bkbhit) ;
   c=buffer[next_out];
   next_out=(next_out+1) % BUFFER_SIZE;
   return(c);
}

void main()
{
   lcd_init(); //lcd'yi çalýþtýr
   
   
   
   printf(lcd_putc,"STARTING"); //lcd ekrana yazý yazdýr
   delay_ms(500);
   
   printf(lcd_putc,"\f2010 SUMMER"); // lcd ekrana yazý yazdýr
   delay_ms(500);
   
   lcd_gotoxy(1,1); // birinci satýr
   printf(lcd_putc,"\f*************");   // lcd ekrana yazý yazdýr
   
   lcd_gotoxy(2,1);  //ikinci satýr
   printf(lcd_putc,"\n**************");
   delay_ms(500);
   
   enable_interrupts(INT_RDA);
   enable_interrupts(global);
   
   
    do {
      delay_ms(1000);
      printf("\r\nBuffered data => ");
      while(bkbhit)
        putc( bgetc() );
   } while (TRUE);
     
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 02, 2010 11:25 am     Reply with quote

Explain the serial port connections. Is one PIC connected to a PC,
at least for the transmitting ? Explain or post a diagram of the
serial port connections.

Also, add the ERRORS parameter to the #use rs232() statement in
both programs. This will prevent a lockup of the UART receiver if one
PIC is receiving characters, but the code is not ready to accept them.
Quote:

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
blackdragon



Joined: 24 May 2010
Posts: 10

View user's profile Send private message

PostPosted: Wed Jun 02, 2010 3:37 pm     Reply with quote

Hi PCM programmer,

I have two pic for communication each other. One of them receiver, other one transceiver. You can see my connection as below;



U1 is a transceiver pic, it captures two information from temp and pressure sensor and sends to RCV receiver pic via rs232 but I have some issue with communication and sources.

Thanks for your help.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 02, 2010 4:57 pm     Reply with quote

Quote:
I've already tried some code pieces but I didn't succeed.
I have some issue with communication and sources.

Explain your problem in detail. Tell the result that you want to get,
and tell the result that you are getting now.
blackdragon



Joined: 24 May 2010
Posts: 10

View user's profile Send private message

PostPosted: Thu Jun 03, 2010 6:25 am     Reply with quote

Hi again,

Actually I want to send couple of data (temperature and pressure) one pic microcontroller to other one with using rs232. I used code as above but I only see nothing.

I've seen lcd put messages, I think my rs232 communication doesnt work well. So if anyone give me any indication I would be more than welcome.

Thanks
jbmiller



Joined: 07 Oct 2006
Posts: 73
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jun 03, 2010 7:27 am     Reply with quote

I'd add proper RS232 level translators(MAX232,etc.) to each PIC.

At least that way you could transmit data to a PC running a 'terminal' program to verify that PIC is running right.

Then you can send data from the PC to the 2nd PIC to verify that PIC is running right.

One step at a time,best to get each PIC running on it's own.
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