View previous topic :: View next topic |
Author |
Message |
lerastas
Joined: 27 Jun 2006 Posts: 3
|
INT_rda disable Interrupts??? |
Posted: Fri Jul 28, 2006 8:24 am |
|
|
Hello everybody, I have a problem.
I want disable interrupts before make a delay.
I have test some way but not good.
If anyone have any idea???
I have tested:
disable_interrupts(INT_RDA);
delay_ms(500);
enable_interrupts(INT_RDA);
disable_interrupt(GLOBAL);
disable_interrupts(INT_RDA);
delay_ms(500);
enable_interrupt(INT_RDA);
enable_interrupt(GLOBAL);
Please help me I don't know why the interrupts stop?
Thanks |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Fri Jul 28, 2006 8:41 am |
|
|
If you are going to be receiving data via RS232 it will be a very BAD idea to disable the RDA interrupt to do a 500ms delay. You could miss a boat load of data by doing this. I really hate using the delay function unless it's very short. The best way to do a delay is to use one of the timers to count up(or down) and then set a bit that will initiate whatever you wanted to be delayed. Try experimenting with the different timers. There are both 8-bit and 16-bit timers. I use them both quite a bit.
Ronald |
|
|
lerastas
Joined: 27 Jun 2006 Posts: 3
|
thanks |
Posted: Fri Jul 28, 2006 9:13 am |
|
|
Yes I have already receive data via the RS232 but i don't want that the delay make not 500ms.
I want disable any interrupts for that my delay is the time specified.
If anyone have another suggestion???
Thanks you for the help
Lerastas |
|
|
Ttelmah Guest
|
|
Posted: Fri Jul 28, 2006 2:52 pm |
|
|
There are two 'parts' to this. You only need to use
'disable_interrupts(GLOBAL);' to actually turn the interrupts off. That having been done, the problem is restarting the interrupts. The INT_RDA interrupt, has the behaviour, that if the data is not retrieved, a second character arrives, and it too is not retrieved, the UART, will go into an 'error' state, and hang. In your 500mSec delay, this is happening.
The 'solution', is to code as follows:
First, add 'errors' to your #use RS232 declaration line. This makes the compiler add code to clear the hang, if it has occured, when you use 'getc'.
Then code the delay as follows:
Code: |
disable_interrupts(global);
delay_ms(500);
while (kbhit()) getc();
enable_interrupts(global);
|
This will force the compiler to flush the UART input buffer of any waiting characters (and because of the 'errors' statement, clear the overrun error bit), before continuing.
Best Wishes |
|
|
stevie_jay Guest
|
Thanks |
Posted: Wed Aug 30, 2006 6:05 am |
|
|
Your solution worked for me, I had the same problem with my UART, trying to enable interrupt half way through a transmission!!!
Thanks |
|
|
|