View previous topic :: View next topic |
Author |
Message |
sander
Joined: 24 Jun 2005 Posts: 5
|
2 interrupts |
Posted: Mon Oct 10, 2005 10:09 am |
|
|
hi ,sorry for my english
I'm writing a program for the pic 16f877a and I want to use 2 interrupts(int rda and int rtcc) but the int rda doesn't work , How can I do? Does anyone have a suggestion ?
thanks in advance |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Oct 10, 2005 10:42 am |
|
|
Post a small test program. |
|
|
sander
Joined: 24 Jun 2005 Posts: 5
|
|
Posted: Mon Oct 10, 2005 1:56 pm |
|
|
the program is similar to this:
#include<16f877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,PUT,BROWNOUT,NOCPD,NOWRT
#use delay(clock=20000000,RESTART_WDT)
#use RS232(BAUD=9600, BITS=8, PARITY=N, XMIT=PIN_C6, RCV=PIN_C7,RESTART_WDT)
#INT_TIMER0
void desplegar()
{
//This function shows on eleven 7-segment display the values of the data that I am procesing, and it works perfectly
}
#INT_RDA
#SEPARATE
void existe_comunicacion()
{
//this function recieves a 7 bytes array and stores it in trama[7]
//using the following routine:
while(i<7)
{
timeout=0;
while(!kbhit() && (++timeout< (tiempo_de_espera*100)))
{delay_us(10);}
if(kbhit())
{
trama[i]=getc();
i=i+1;
bandera=1; }
else
{
i=8;
bandera=0; } //cambiar a 0
}
//bandera tells me wether or not the 7 bytes has arrived
}
void main()
{
set_timer0(0);
setup_counters( RTCC_INTERNAL, RTCC_DIV_16 | RTCC_8_BIT); //RTCC_DIV_64 para 20M
//RTCC_DIV_32=1,6ms
enable_interrupts(INT_RTCC); //RTCC_DIV_8 para 4M
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(1)
{
//The pic does all here (i.e read a keyboard chance values,etc)
}
}
Actually, the program has more than 1500 lines I probed the comunication routines alone and they work, the problem is when I put the 2 interrupts together, the program doesn't do the comunication.
sander. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Oct 10, 2005 1:59 pm |
|
|
Probably UART overflow. Try this
#use RS232(BAUD=9600, BITS=8, PARITY=N, XMIT=PIN_C6, RCV=PIN_C7,RESTART_WDT,ERRORS) |
|
|
sander
Joined: 24 Jun 2005 Posts: 5
|
|
Posted: Mon Oct 10, 2005 2:12 pm |
|
|
there isn't a uart overflow because I tested all the communication routines that I made one by one and they work well, in addition when I disable the rtcc interrupt the communication works well
sander |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Oct 10, 2005 2:14 pm |
|
|
sander wrote: | there isn't a uart overflow because I tested all the communication routines that I made one by one and they work well, in addition when I disable the rtcc interrupt the communication works well
sander |
Sounds exactly like an overflow problem. Just try it! |
|
|
sander
Joined: 24 Jun 2005 Posts: 5
|
|
Posted: Mon Oct 10, 2005 2:33 pm |
|
|
I can't believe it but now it is working better, but just arrive well 3 bytes but I think that I can solve that , thank you very much
sander |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Oct 10, 2005 2:35 pm |
|
|
Interrupts need to be short. Putting delays in an interrupt routine can cause you problems. I suspect that you Timer0 interrupt routine is too long causing you to miss the communication interrupt and thus get the overflow problem. |
|
|
|