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

serial interrupt

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







serial interrupt
PostPosted: Mon Oct 17, 2005 3:19 am     Reply with quote

i am having a few diffucilties in serial_isr. pic cannot receive serial data because the serial_isr doesnt work.. here is the code. what is missing?

Code:


#include <16F877.h>
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,XT, PUT, NOPROTECT, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,FORCE_SW)
//#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)

int index=0;
byte buffer[2];

#int_RDA
void serial_isr()
{
   //output_high(pin_D2);
   buffer[index]=getch();
   index++;
   if (index==2) index=0;   
}



void main()
{
   int i=0;
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   set_tris_b(0);
   output_b(0);
   set_tris_d(0);
   output_d(0);
   for(i=0;i<3;i++)
      buffer[i]=0;
   index=0;
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);

while(1)
{
   output_b(buffer[0]);
   output_d(buffer[1]);
}

}
Ttelmah
Guest







PostPosted: Mon Oct 17, 2005 3:40 am     Reply with quote

You cannot have a serial interrupt with a software UART...
Get rid of the 'force_sw' in the port setup. Also add 'errors', which will stop the port locking up if data is not processed fast enough.

Best Wishes
hayy
Guest







PostPosted: Mon Oct 17, 2005 4:53 am     Reply with quote

additions are made but no action yet Sad
Ttelmah
Guest







PostPosted: Mon Oct 17, 2005 5:12 am     Reply with quote

Though it should work, the problem may be that the code as written is just missing the interrupts. You are accessing the array continuously in the external loop, which will imply that interrupts are disabled for this access (since the array is also accessed in the interrupt routine). There is a good chance therefore that the routine will not be called.
Try:
Code:

#include <16F877.h>
#device adc=8
#use delay(clock=4000000)
#fuses NOWDT,XT, PUT, NOPROTECT, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,ERRORS)

int index=0;
byte buffer[2];
int1 received=false;

#int_RDA
void serial_isr()
{
   buffer[index]=getch();
   index = (index+1)&1;
   received=true;   
}

void main()
{
   int i=0;
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   'set_tris_b(0);
   output_b(0);
   'set_tris_d(0);
   output_d(0);
   You are not using fast_io, so do not need to set tris.
   for(i=0;i<3;i++)
      buffer[i]=0;
   index=0;
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);

   while(1)  {
       if (received) {
          received=false;
          output_b(buffer[0]);
          output_d(buffer[1]);
      }
  }
}


Best Wishes
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

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

PostPosted: Mon Oct 17, 2005 7:05 am     Reply with quote

Ttelmah wrote:
Though it should work, the problem may be that the code as written is just missing the interrupts. You are accessing the array continuously in the external loop, which will imply that interrupts are disabled for this access (since the array is also accessed in the interrupt routine). There is a good chance therefore that the routine will not be called.


I don't think this will be an issue. If a character has arrived into the UART serialization buffer the interrupt flag will be set irresepective of when main processes the array the character received will be output to the port. The main loop is too short for characters to be missed given the baud rate and clock frequency. This also means that overrun would be unlikely.

I would look for a basic hardware problem.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!


Last edited by asmallri on Mon Oct 17, 2005 9:06 am; edited 1 time in total
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Mon Oct 17, 2005 9:03 am     Reply with quote

I´m also guess that you have a basic hardware problem.
Run this short code to be sure that your RS232 hardware was properly wired,
then try it with buffer + interupts.

Code:


#include <16F877.h>
#fuses XT, NOWDT,PUT, NOPROTECT, BROWNOUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

main()
{
char c;

  printf(" test > ");

while(1)
  {
   c = getc();       
   putc(c);     
  }
}



Humberto
Ttelmah
Guest







PostPosted: Mon Oct 17, 2005 10:41 am     Reply with quote

I would agree that a hardware problem is the most likely, but the problem I was thinking of, is one that I have seen on a couple of CCS releases. The compiler will disable interrupts for the entire array access, if it is used both inside and outside the loop. If the loop only contains array accesses, I have seen a couple of occasions, where the optimiser (especially with high optimisation settings), dealing with a loop like this, ends up putting the 'loop' jump inside the disable_interrupt section, resulting in the interrupts being left disabled. Even adding a single instruction (like a nop, or a delay), prevents it happening. It is a bug, but one that given the structure of the program, _might_ just be happening.

Best Wishes
hayy
Guest







PostPosted: Tue Oct 18, 2005 3:58 am     Reply with quote

i ve already tried the
c=getch();
putch(c);

but i checked that com port works proper (loop back connect) but when i use getc function pic cannot receive data though it can send.
i am goning to try the operation with the receive flag . thanks
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Oct 18, 2005 6:54 am     Reply with quote

Quote:
but i checked that com port works proper (loop back connect)


Are you saying that when you connected the Tx & Rx together that is recieve worked? If so, the problem is not with the PIC but rather the connections and/or the transmitting device.
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