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

how to enable and disable interrupt (INT_RDA)

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



Joined: 16 Jul 2021
Posts: 1

View user's profile Send private message

how to enable and disable interrupt (INT_RDA)
PostPosted: Fri Jul 16, 2021 12:47 pm     Reply with quote

I am working with various interruptions. To start I need to enable an INT_TIMER0 interrupt, but to be able to enable this interrupt I disable the interrupt (INT_RDA), at the end of the interrupt (INT_TIMER0). I don't know how to enable the interrupt (INT_RDA) correctly.
The code is something like that:
Code:

#int_timer0
VOID timer_0()

//instructions (some time)
//t=1;
// disable_interrupts(int_timer0);
 } 

#INT_RDA
void RDA()
{
read_string();
}

void main()
{
while(true)
  {
   disable_interrupts(int_timer0);
   if(s1==1)
    { 
     disable_interrupts(int_RDA);
     enable_interrupts(int_timer0);
    }
   if(t==1) enable_interrupts(int_RDA);
  }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 16, 2021 2:34 pm     Reply with quote

I don't see where you enable global interrupts. You need to.
Add the line shown below in bold:
Quote:
void main()
{
enable_interrupts(GLOBAL);
.
.
.

temtronic



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

View user's profile Send private message

PostPosted: Fri Jul 16, 2021 2:41 pm     Reply with quote

Hopefully your 'read_string()' function is a timed event, otherwise if (when..) you don't get a complete string from the outside, the PIC will sit in the ISR forever.....

CCS does supply info about this, I believe it's in the FAQ section of the manual.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun Jul 18, 2021 12:34 am     Reply with quote

Also understand, the 'INT_RDA' says that _one_ character has been
received, not a 'string'. To read a sequence of characters you really need
to be using something like the get_string function from input.c, modified to
fetch it's characters from the circular buffer routine in ex_sisr.c
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun Jul 18, 2021 11:36 pm     Reply with quote

Also, another 'key' point. If you are disabling INT_RDA anywhere, it is
absolutely 'vital', that you have ERRORS in your RS232 declaration.
This should always be there (unless you add your own error handling), but
if a character can be missed (which disabling makes likely), becomes
'essential', otherwise the UART can become hung. Sad

There are several more things to say. Unless you are using the hardware
interrupt priority feature (which means you have an interrupt flagged
as 'FAST', or 'HIGH'), when you are inside an interrupt handler, _all_
other interrupts are disabled. In general interrupts cannot interrupt other
interrupts. So the 'disabling' of INT_RDA, is pointless. If you are staying
for a significant time inside an interrupt handler, you are preventing all
the other interrupts from doing the jobs they are meant to do. In general,
the old 'rule of thumb', is you should always get out of interrupts as quickly
as possible. If you want a task that takes significant time to be triggered
by a timer, then set a flag, and handle this in the main code, when the
flag happens. If you want to disable serial reception while this is happening,
then have a flag, which is set when this happens and have the serial receive
routine simply read characters when this is set, and not store them. This
avoids triggering hardware errors because the characters are not handled.

Your approach at the moment is fundamentally flawed, which may explain
why you are having problems... Sad
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