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

INT_RDA and INT_RDA2

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



Joined: 29 Dec 2016
Posts: 2

View user's profile Send private message

INT_RDA and INT_RDA2
PostPosted: Thu Dec 29, 2016 4:47 pm     Reply with quote

Hola buen día , estoy realizando un pequeño proyecto en el cual tengo que utilizar las interrupciones de los dos puertos seriales que posee el PIC18F25K22. El código es el siguiente.

Hi, good morning, I'm doing a little project in which I have to use the interruptions of the two serial ports that the PIC18F25K22 has. The code is as follows.


Code:
#include <18F25K22.h>
#device ADC=10
#use delay(internal=8MHz)
#priority INT_RDA,INT_RDA2
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)
#use rs232(baud=19200,parity=N,xmit=PIN_B6,rcv=PIN_B7,bits=8,stream=PORT2)

#INT_RDA
void  RDA_isr(void)
{

   fprintf(PORT1,"HOLA1");

}

#INT_RDA2
void  RDA_isr2(void)
{
   fprintf(PORT2,"HOLA2");
}

void main()
{

   
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_RDA2);

   while(TRUE)
   {
      //TODO: User Code
   }

}


Por lo cual si yo mando información por el primer puerto estaré reviviendo un hola1 y por el contrario si yo envió información por el segundo puerto estaré reviviendo hola2.
El problema empieza cuando yo le mando información por el primer o segundo puerto y al entrar a la interrupción esta se repite infinitamente sin algo que la detenga, en otras palabras , cuando yo le envio un carácter por cualquier puerto , infinitamente me devuelve hola1 o hola2.

No entiendo por que se queda metido en un ciclo la interrupción. Espero alguien me pueda orientar. Gracias



So if I send information on the first port I will be receiving a hello1 and on the other hand if I sent information on the second port I will be receiving hello2 .
The problem starts when I send information for the first or second port and when entering the interruption it repeats itself infinitely without something stopping it, in other words, when I send a character to it by any port, infinitely it returns hello1 or hello2 .

I do not understand why the interruption is in a cycle. I hope someone can guide me. Thank you.


Last edited by George96 on Thu Dec 29, 2016 5:57 pm; edited 1 time in total
George96



Joined: 29 Dec 2016
Posts: 2

View user's profile Send private message

Re: Interrupciones del Puerto Serial
PostPosted: Thu Dec 29, 2016 4:56 pm     Reply with quote

My compiler version is 5.061
temtronic



Joined: 01 Jul 2010
Posts: 9162
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Dec 29, 2016 8:06 pm     Reply with quote

generally speaking...
When you send a character to the PIC UART you MUST read the UART buffer to clear the interrupt. If you don't ,then the PIC will enter the ISR, do what's there, then leave BUT as soon as it leaves the ISR it sees the Interrupt flag set so it goes to the ISR, do what's there, then leave....... it'l do this until you clear the interrupt flag, which is done by reading the UART buffer.


The other thing you MUST do is add 'errors' to the use RS232(...... options....) .The HW UART buffer is 2-3 characters so if YOU don't clear(read) them #4 will 'hang' the PIC.

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 29, 2016 8:09 pm     Reply with quote

I see that Temtronic posted about the same time as me. I'll leave my
post up anyway.
-------------------

You have to actually read the received byte in the #int_rda or #int_rda2
routine with fgetc(). Example:
Code:

#INT_RDA
void  RDA_isr(void)
{
int8 temp;

temp = fgetc(PORT1);   // Get the char to clear interrupt

fprintf(PORT1,"HOLA1");

}


Also, it's not normally a good idea to do lengthy procedures, such as
sending a string, while inside an interrupt routine. It's OK to do this
in a test program, where you press a key and you see a response
on the serial terminal. But a programmer does not normally do this
in a real program.
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