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

Always in #INT_RDA

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







Always in #INT_RDA
PostPosted: Thu Apr 27, 2006 4:40 am     Reply with quote

Hi,
I'm having problems with #INT_RDA, because I don't send any data via RS232 and PIC is always in this interrupt (Even if I disconnect the uart pins)
I use PIC16F873.
I need help. How can I stop the INT_RDA?
The code is:

Code:


#include <16F873.h>

#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=8000000)


#use fast_io(A)   
#use fast_io(B) 
#use fast_io(C)   

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, bits=8, parity=N)


#define LED1   PIN_A2
#define LED2   PIN_A3
#define LED3   PIN_B3

int1 flag_SO;

int1 rx; //Para activar la recepcion del puerto RS232


#INT_RDA
void intrda_isr(void)
{
   output_high(LED1);
   output_high(LED3);
   output_high(LED2);
}


#INT_EXT
void ext_isr()
{
   flag_SO=1;
}

// ------------------------Configuracion del PIC -----------------------------//
void config_pic(void)
{

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);

//  Configuración de los puertos del PIC
   SET_TRIS_A(0x00); // configuramos todos los pines como salidas
   SET_TRIS_C(0x80);  //1000 0000: C7:entrada, resto y C6:salida

}


//--------------------------MAIN----------------------------------------------//
void main (void)
{

config_pic();

enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
enable_interrupts(INT_EXT);
ext_int_edge( L_TO_H );

output_low(LED1);
output_low(LED2);
output_low(LED3);

rx=0;

while(1)
{
 if(rx==1){
      rx=0;
   //AQUI REALIZABA UN GETS();

 }else{ //del rx==1
   output_low(LED1);
   output_low(LED2);
   output_low(LED3);

    if (flag_SO==1)
     {
        flag_SO=0;
         printf("PRUEBA");

     }
 }//fin else
}//fin while(1)
}//fin main




Thanks in advance for your help.
RHA



Joined: 25 Apr 2006
Posts: 31
Location: Germany

View user's profile Send private message

PostPosted: Thu Apr 27, 2006 5:11 am     Reply with quote

I think you have to read out the receive buffer in the interrupt service routine to clear the flag for the interrupt.


Greets
RHA
Guest








PostPosted: Thu Apr 27, 2006 5:32 am     Reply with quote

RHA wrote:
I think you have to read out the receive buffer in the interrupt service routine to clear the flag for the interrupt.


Greets
RHA


I have tested it and I have to do a getc(). But if I want to do a gets() I have problems.
I've found out an error in CCS. Initially the usart interrupt flag is enable and so when I enable INT_RDA, I enter in this interruption.
I think the solution is to do a getc() before enable_interrupts(INT_RDA), but this in't correct.
Mark



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

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

PostPosted: Thu Apr 27, 2006 6:30 am     Reply with quote

No, you would receive the data into a buffer. From main, you can check this buffer for your string.
Guest








PostPosted: Thu Apr 27, 2006 8:11 am     Reply with quote

Mark wrote:
No, you would receive the data into a buffer. From main, you can check this buffer for your string.

The problem is that if I don't send any data by RS232, PIC doesn't have enter in UART interrupt (INT_RDA) when I start my program
Mark



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

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

PostPosted: Thu Apr 27, 2006 9:06 am     Reply with quote

Anonymous wrote:
Mark wrote:
No, you would receive the data into a buffer. From main, you can check this buffer for your string.

The problem is that if I don't send any data by RS232, PIC doesn't have enter in UART interrupt (INT_RDA) when I start my program


I have no idea what you are trying to say. There is no problem with what I suggested. Maybe with you understanding though. Why do you think that your PIC needs to enter UART interrupt when program starts? The PIC will only enter the interrupt when an even occurs. If no RS232, then no data in buffer. I guess you need to better describe what you are trying to do.
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Thu Apr 27, 2006 12:21 pm     Reply with quote

Guest, from the data sheet "Flag bit RCIF is a read only bit, which is cleared by the hardware. It is cleared when the RCREG has been read and is empty".

You have enabled this interrupt in your code but in your interrupt handler you are not reading from the RCREG. Is this why you stay in the interrupt routine?

Read the data sheet.
_________________
David
dbotkin



Joined: 08 Sep 2003
Posts: 197
Location: Omaha NE USA

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

PostPosted: Thu Apr 27, 2006 1:20 pm     Reply with quote

According to the 16F873 date sheet the RCIF bit *should* be cleared by a reset, so in theory you shouldn't see INT_RDA unless the USART thinks it has data.

That said, the USART can think it has data if you have, for example, a floating input or some other hardware oddness that allows the USART to think it's seen a start bit.

Here's what I would do: First, add ERRORS to your #use rs232 statement. I've never had a project work right without it. Second, read RCREG inside your serial ISR; this will clear RCIF and keep you from constantly looping into it if and when RCIF gets set.

It would be interesting to know why RCIF is getting set when it shouldn't. You can work around it with a little bit of code, but it's best not to let those unexplained things slide, even if you do work around them. Digging until you find the source of the problem is a good way to learn, and will often keep other problems from coming up later on.
Gsmar
Guest







PostPosted: Fri May 05, 2006 4:53 am     Reply with quote

Thanks for your help. Finally I solve the problem. The device I connect to the uart, at the begining it sends a character and I don't read this, and so The pic always is on interrupt.
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