View previous topic :: View next topic |
Author |
Message |
FFT
Joined: 07 Jul 2010 Posts: 92
|
int_rda does not work after a time |
Posted: Wed Jul 14, 2010 8:38 am |
|
|
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: 19513
|
|
Posted: Wed Jul 14, 2010 9:24 am |
|
|
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
|
|
Posted: Wed Jul 14, 2010 10:11 am |
|
|
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
|
|
Posted: Wed Jul 14, 2010 12:43 pm |
|
|
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
|
|
Posted: Wed Jul 14, 2010 5:06 pm |
|
|
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
|
|
|
FFT
Joined: 07 Jul 2010 Posts: 92
|
|
Posted: Thu Jul 15, 2010 6:33 am |
|
|
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 |
|
|
|