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 problem of two PIC communication

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







RS232 problem of two PIC communication
PostPosted: Sat Sep 19, 2009 1:05 pm     Reply with quote

Hi all.

I'm trying to communicate 16f877 and 18f4550 with rs232. I just want to see they are communicating to start my real project but I am in trouble!

16f just sends a "sss" word with puts() function (when I press b7 button), and 18f takes it and prints "GELDI" on the lcd screen. However when I start the program and press the button 16f sends the word once, 18f gets in int_rda interrput and writes "GELDI" on LCD however it always gets in int_rda interrupt, although I send "sss" word only once.

Shortly 18f can not get out from int_rda interrupt.

Here is my 18f codes:
Code:

#include "C:\Documents and Settings\SER\Desktop\ockd\PIC\(19.09.2009) RS232 TRIAL 18f-16f\18f\18F_RS232.h"
#use fast_io(d)
#define use_portd_lcd TRUE
#include <lcd.c>
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,stop=1)

#int_rda
void rs232_kesme()
{
   disable_interrupts(int_rda);
   lcd_init();
   delay_ms(1000);
   printf(lcd_putc,"GELDI");
   delay_ms(1000);
}

void main()
{
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
   set_tris_d(0x00);
   output_d(0x00);
   delay_ms(2000);
   lcd_init();
   printf(lcd_putc,"READY"); /to see PIC is ready
   delay_ms(1000);
   
   enable_interrupts(global);
   
   while(1)
   {
   enable_interrupts(int_rda);
   }

}

I used to disable interrupt as shown but then it works only once. If I enable it as shown (as done in my book) when I enable the interrupt it again (immediately after enabling) gets in the int_rda interrupt (but there is no word send).

Here is my 16f code:
Code:

#include "C:\Documents and Settings\SERN\Desktop\Lod\PIC\(19.09.2009) RS232 TRIAL 18f-16f\16f\16F_RS232.h"
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,stop=1,timeout=10)

#int_RB
void kesme()
{
   if(input(pin_b7))
   {
      puts("sss");
   }

}

void main()
{
   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);

   enable_interrupts(int_rb);
   enable_interrupts(global);
}


What can be the problem that I can not solve?
Ttelmah
Guest







PostPosted: Sat Sep 19, 2009 1:36 pm     Reply with quote

INT_RDA, will occur for as long as a character is waiting in the serial RX buffer. You never read the receive character, so the buffer _will_ always have a character, once a character is received. Inside INT_RDA, you _must_ read the character....
The interrupt occurs for _each individual character_.

Best Wishes
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Sat Sep 19, 2009 1:43 pm     Reply with quote

And another problematic thing I noticed is that you use Delay in interrupt routine. That is BAD practice.

It would be better if you would use ISR just for receiving and if the condition (buffer = sss) would be true, then you set the flag to output the message on the LCD, and you would do that in main part of program.
srkn
Guest







PostPosted: Sun Sep 20, 2009 9:04 am     Reply with quote

Thanks for quick replies.

I read the char value and cleared delays and write to LCD in main function that problem is solved, but some other problem occured.

If I send one char value with 16f, 18f takes irrelevant char values. And if I try to take string values, It can not finish taking the string value "aaa" and program can not pass gets() function.

Here are my new 18f codes:
Code:

#include "C:\Documents and Settings\S\Desktop\Lo\PIC\(19.09.2009) RS232 TRIAL 18f-16f\18f\18F_RS232.h"
#use fast_io(d)
#define use_portd_lcd TRUE
#include <lcd.c>
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,stop=1)

char yazi;  // to take string I change it with the "char yazi[4];" command.
int i;  // if it gets in interrupt, i becomes 1 to use in main function

#int_rda
void rs232_kesme()
{
   disable_interrupts(int_rda);
   yazi=getc()  //if I take string I change it with the command: "gets(yazi);"
   i=1; //to understand it get in the interrupt.
}


void main()
{
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   
   set_tris_d(0x00);
   output_d(0x00);
   lcd_init();
   printf(lcd_putc,"READY");
   
   enable_interrupts(int_rda);
   enable_interrupts(global);
   
   while(1)
   {
      enable_interrupts(int_rda);

      if(i==1) // if interrupt occured
      {
         i=0;
         printf(lcd_putc,"%c",yazi);  //If I take string values I change %c to %s
      }
   }

}


Here is the command of 16f:
Code:

#include "C:\Documents and Settings\SE\Desktop\Loc\PIC\(19.09.2009) RS232 TRIAL 18f-16f\16f\16F_RS232.h"
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,stop=1,timeout=10)

#int_RB
void kesme()
{
   if(input(pin_b7))
   {
      putc('b'); //If I send string value, I change it with the command: "puts("aaa");"
   }

}


void main()
{
   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);

   enable_interrupts(int_rb);
   enable_interrupts(global);
}

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