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 does not work after a time

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



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

int_rda does not work after a time
PostPosted: Wed Jul 14, 2010 8:38 am     Reply with quote

Hi,

I use 18F4520 and its hw uart, but in my code I'm doing sometimes:
Code:
disable_interrupts(GLOBAL);
hold_regs[Number] = Value;
enable_interrupts(GLOBAL);

for recording of the calculated values in an array of modbus.

With a master pic I get the hold_regs content using modbus.
BUT, sometimes the connection become broken and the master can't read nothing. when this happen 1 time, master can't read nothing until I reset the slave pic.
My opinion is the problem occurs because of these enable/disable interrupt routines. I tried to add after enable_interrupt code a clear_interrupt(int_rda) too but there is no change.

In my code there are no other functions (delay etc) which disables interrupts.
I think, when the master pic requests something and at the same time slave pic disables interrupts, at this time the problem is beginning and it continues until resetting of the slave.

After happening of this problem, the slave pic never enters in the int_rda routine. (I put there a led)

BTW: I disable interrupts because the hold_regs variable is used both in interrupt code and main.

How can we resolve or workaround this problem?

CCSv4.107

Br
Ttelmah



Joined: 11 Mar 2010
Posts: 19348

View user's profile Send private message

PostPosted: Wed Jul 14, 2010 9:24 am     Reply with quote

I doubt if that is the problem. Probably something else that takes longer. Check the warning window when compiling. Is there any mention of interrupts being disabled?. What other interrupt handlers have you got?. How long will they take to execute?.
I also doubt that "the slave pic never enters in the int_rda routine"...
The problem almost certainly has already happened, on the _last_ time the slave enters the INT_RDA.

Have you got 'ERRORS' in the RS232 declaration?.
If not, then either put it there, or you need to be adding error handling yourself to the interrupt handler.

Key thing is that if the receive buffer overruns (just two characters), the slave _will_ call the interupt handler, _but_ if the error is not cleared, when you leave the handler, the receive component of the UART, _will_ be hung....

Now, the code you show here only takes a few machine cycles to execute, so is unlikely to be the problem. But if (for instance), you have another interrupt handler, that takes significant time, or a function in the main, and in an interrupt handler - this will result in interrupts being disabled for the entire duration of this function in the main - much more likely to be a problem....

Best Wishes
FFT



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

PostPosted: Wed Jul 14, 2010 10:11 am     Reply with quote

Hi Ttelmah, thanks for the answer.

I use 2 timer interrupts, one of them occurs in every 65ms and it is:
Code:
#int_TIMER1
void  TIMER1_isr(void) // enters here in every 8 x 8.2ms = 65.6ms
{
   LedBlink=~LedBlink; // toggle the led

   if(MeasurePeriod)
      MeasurePeriod--;

   if(GeneralTimer)
      GeneralTimer--;
}

The other timer interrupt is in modbus.c, it occurs only for timeout, when received a character. it is short too.

I don't have ERRORS.

Ttelmah wrote:
I also doubt that "the slave pic never enters in the int_rda routine"...
The problem almost certainly has already happened, on the _last_ time the slave enters the INT_RDA

I think the problem is connected with this words.
But I want in my program if I have disabled all interrupts for 20ms and the master requests something at the same time, let the master just has timeout error (12) and after a time will try again to get data. But at this time happens an error which I don't know, and all the communication dies. The slave never enters again in the int_rda routine.
Is not there a way to do that when interrupts are enabled, everything is OK, but when interrupts are disabled, the master can't get information and has to wait a little time to try again ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 14, 2010 12:43 pm     Reply with quote

Quote:
But at this time happens an error which I don't know, and all the communication dies. The slave never enters again in the int_rda routine.

Do as Ttelmah says, and add the ERRORS parameter to the #use rs232()
statement for your hardware UART. This will fix the lock-up problem
with the hardware UART.
FFT



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

PostPosted: Wed Jul 14, 2010 5:06 pm     Reply with quote

OK, I've added ERRORS there but I'm getting a warning "variable never used: rs232_errors"

Should I add other code which watches in rs232_errors variable? I never used this parameter.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 14, 2010 5:12 pm     Reply with quote

Just ignore the warning, or disable it in the Build options menu
or use a trick to make it go away:
http://www.ccsinfo.com/forum/viewtopic.php?t=33634
FFT



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

PostPosted: Thu Jul 15, 2010 6:33 am     Reply with quote

I was thinking that we will handle the variable with a switch case and will understand when happens error, then will clear interrupt or will do something like that.

I'm gonna test it some time with ERRORS option.

Thanks all
Best wishes
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