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_RTA and reading a string

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



Joined: 17 May 2005
Posts: 213

View user's profile Send private message

INT_RTA and reading a string
PostPosted: Fri Dec 02, 2005 8:04 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Dec 02, 2005 8:51 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Dec 02, 2005 8:59 am     Reply with quote

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







PostPosted: Fri Dec 02, 2005 9:26 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Dec 02, 2005 9:34 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Dec 02, 2005 10:35 am     Reply with quote

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.
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