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

RS232 interrupts

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







RS232 interrupts
PostPosted: Mon Dec 14, 2009 9:27 am     Reply with quote

Hi,

I've tried the example EX_SISR.c but it didn't seem to work properly for me. It doesn't print the characters which I entered through Hyperterminal. It only prints "Running..." and "Buffered Data =>". I tried printing an 'a' as shown in the code below, and it managed to print it only the first time I tried to do the interrupt. Anyone can help me with this? Thanks.

Code:

#if defined(__PCM__)
#include <18F2620.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=12000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#elif defined(__PCH__)
#include <18F2620.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=12000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#elif defined(__PCD__)
#include <18F2620.h>
#fuses HS, NOWDT, NOPROTECT
#use delay(clock=12000000)
#use rs232(baud=9600, UART1A)
#endif

#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() {

   enable_interrupts(int_rda);
   #if defined(__PCD__)
   enable_interrupts(intr_global);
   #else
   enable_interrupts(global);
   #endif

   printf("\r\n\Running...\r\n");

               // The program will delay for 10 seconds and then display
               // any data that came in during the 10 second delay

   do {
      delay_ms(10000);
      printf("\r\nBuffered data => ");
      while(bkbhit)
      {
        putc( bgetc() );
        putc('a');
       }
   } while (TRUE);
}
snowbell
Guest







PostPosted: Mon Dec 14, 2009 10:12 am     Reply with quote

By the way, i'm using compiler version 4.057. Thanks.
snowbell
Guest







PostPosted: Tue Dec 15, 2009 12:25 am     Reply with quote

I've also tried this very simple code of receiving a char and then displaying it on HyperTerminal. It still doesn't display, the char that I entered in HyperTerminal. It can print "Start:" and only show 'a' the first time, after that, it seems to hang. Can anyone help please. Thanks.

Code:

#include <18F2620.H>
#fuses HS, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP   
#use delay(clock=12000000)                           
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//=================================
void main()
{
char c;

printf("Start: ");

while(1)
  {
        c = getc();
        putc(c);
   putc('a');
  }
 
}   
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Dec 16, 2009 1:17 am     Reply with quote

it's always a good idea to TEST to see if there is a char in the RX buffer before doing a getc().

In CCS-C that's most easily accomplished with kbhit();

Also, what kind of data are you receiving, ASCII or binary?

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
LegolasMicrochip



Joined: 28 Jun 2009
Posts: 1

View user's profile Send private message

PostPosted: Tue Dec 22, 2009 6:58 am     Reply with quote

It actually does not hang, in fact its waiting for the character. Until or unless it does not receive a new character it would keep waiting on the getc().
So if you would type a character through your hyperterminal then it would display 'a' again.
Also verify that your circuit is correct.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

to make it clearer and faster try this hack
PostPosted: Tue Dec 22, 2009 4:43 pm     Reply with quote

Code:

// useless ->   delay_ms(10000);
      printf("\r\nBuffered data =>\r ");
do {
         while(bkbhit)
      {         putc( bgetc() );         putc('a');    }
   } while (TRUE);
}


U only see the setup print out - once and the delay does NOTHING useful anyway IF the ISR is actually working - each line with CR U send will be on a line of its own - minus all the 'a's
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