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 RS232 Port Locks Up

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



Joined: 26 Feb 2004
Posts: 11

View user's profile Send private message

PIC RS232 Port Locks Up
PostPosted: Sat Jun 12, 2004 3:13 pm     Reply with quote

Hello all,

I have a problem sending data to the PIC rs232 port from an external application. If I try and send anything more than 3 or 4 bytes in a stream, the INT_RDA hangs up and the PIC won't accept any more data until it get's reset. Do I need to throttle the send rate? or choose another baud? It's already so slow (9600).

To see what I mean, here's a sample program for the PIC, I used the CCS SIOW macro utility to send multiple bytes over a 232 cable from my PC. (In SIOW choose the macro menu command and add a macro that sends multiple bytes) A 3 byte macro works fine, but a 10 byte macro hangs the PIC's serial port every time.

Any ideas?
Compiler version is 3.190
Here's the code:

Code:
#include <16F877A.h>
#device ICD=TRUE
#fuses HS,NOLVP,NOWDT,PUT
#use delay (clock=20000000)

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

#define STATUS_LED   PIN_A5

int32 byteCount = 0;


#INT_RDA
void serial_isr()
{

   byteCount++;
   printf("%X ", getc());
   printf("%lu, ", byteCount);
}


void main()
{
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);   
   printf("\r\nRunning serial interrupt test\r\n");

   while(TRUE)
   {
      output_low(STATUS_LED);
      delay_ms(500);
      output_high(STATUS_LED);
      delay_ms(500);
   }
}
Guest








PostPosted: Sat Jun 12, 2004 3:59 pm     Reply with quote

You are only able to receive something like 3 or 4 characters? This sounds like a problem in the RS232 receive because the UART is only able to buffer 2 characters in the FIFO while receiving a 3rd character. After receiving this 3rd character the overrun error bit is set and you will get continous RDA interrupts until you reset this error flag. Very likely this is what causes your program to hang.

So what could cause this error? Your interrupt handler is taking too long!!
Code:
printf("%X ", getc());

Everytime you receive 1 character you want to send 3 characters. This is not gonna work....

Advice 1: Never use printf in your interrupt handlers. It takes too long.
Advice 2: Add the 'errors' parameter to your '#use rs232' command for automatic clearing of the overrun error bit.
doug_h



Joined: 26 Feb 2004
Posts: 11

View user's profile Send private message

PostPosted: Sat Jun 12, 2004 6:59 pm     Reply with quote

Thanks so much for the help. Now I understand the problem.

Cheers!
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