View previous topic :: View next topic |
Author |
Message |
arrow
Joined: 17 May 2005 Posts: 213
|
INT_RTA and reading a string |
Posted: Fri Dec 02, 2005 8:04 am |
|
|
Hi
I am using the pic16f873 and I would like to detect something comming down the RS232 line from the PC.
I have implemented an INT_RTA and it works fine with a getc() in the interrupt routine.
When I send more than one character down the RS232 line however things dong work. I am assuming that the INT_RTA gets called every time there is a character going down the line?
What is the solution for reading multiple characters and having the Microchip "listen" when this even occurs?
Thank you in advance.
a. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Dec 02, 2005 8:51 am |
|
|
Quote: |
I have implemented an INT_RTA and it works fine with a getc() in the interrupt routine
|
But we doesn´t know how you do it.
Quote: |
What is the solution for reading multiple characters and having the Microchip "listen" when this even occurs?
|
CCS gives you an example on how to implement an interrupt driven routine that
solve your problem: EX_SISR.C
To understand clearly what´s going on inside the UART, I recomend to read the
Mid-Range MCU Family Reference Manual.
http://www.cs.indiana.edu/Facilities/hardware/B442_inv_pend/midrange.pdf
Read Section 18.4.2 USART Asynchronous Receiver
Humberto |
|
|
arrow
Joined: 17 May 2005 Posts: 213
|
|
Posted: Fri Dec 02, 2005 8:59 am |
|
|
Hi Humberto
Thank you for your suggestion. I have a quick question for you:
Can I disable interrupts within an interrupt? Something like this?
Code: |
//***RS232 interrupt
#int_rda
void RS232(){
int ch;
disable_interrupts(GLOBAL);
ch = getc();
if(ch==84){
Command = 84;
minutes = getc() - 48;
zero = true;
int_count = 0;
seconds = 0;
}
enable_interrupts(GLOBAL);
}
|
Thank you
a. |
|
|
Ttelmah Guest
|
|
Posted: Fri Dec 02, 2005 9:26 am |
|
|
No, No, NO.....
Never _ever_ change the global interrupt setting inside an handler.
The chip _itself_ disables the global interrupt when an interrupt handler is called. It resets it on the actual return instruction in the INT_GLOBAL handler (this is a special 'return' instruction to do this). The first 'disable' does nothing (interrupts have allready been disabled by the hardware). However, if you enable the interrupts as shown, you are still potentially inside the handler code, and if an interrupt flag is set, you will get interrupts that are 'calling themselves' (recursion), which the chip _does not support_, resulting in registers getting corrupted....
This is an absolute 'no no', on the PIC.
Best Wishes |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Dec 02, 2005 9:34 am |
|
|
If you disable_interrupts(GLOBAL) inside an INT_RDA what you get is what you do, next char of the expected string would be disable to receive. Anyway, it doesn´t make any sense to disable and then enable a GLOBAL interrupts inside the interrupt handler. In some cases it will be need to disable a specific peripheral (INT_EXT, INT_RTCC) but NOT a GLOBAL.
I guess that you doesn´t want any disturbance while you are receiving a string, but disabling a GLOBAL is not the way to do that.
An interrupt handler should be as short as possible. Just set a flag or store incoming chars in a buffer and quit. All other stuff must be done in main.
Search for "circular buffer" in this forum and learn how to do it.
http://www.ccsinfo.com/forum/viewtopic.php?t=18974&highlight=buffer+rs232
http://www.ccsinfo.com/forum/viewtopic.php?t=19117&highlight=
Humberto |
|
|
arrow
Joined: 17 May 2005 Posts: 213
|
|
Posted: Fri Dec 02, 2005 10:35 am |
|
|
Thank you guys!
I think I have solved the problem by storing each char into an array and then processing the array.
(printf in the interrupt caused a mysterious problem- but once I removed it as Humberto suggests- things are now good).
Regards
a. |
|
|
|