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 CCS Technical Support

Interrupts problem with RS232

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Patrik �kerlind
Guest







Interrupts problem with RS232
PostPosted: Fri Dec 06, 2002 11:31 am     Reply with quote

Hi
I have interrupts problem with RS232.
When i don't want anny more interrupts I
disable_interrupts(GLOBAL); // all interrupts OFF
disable_interrupts(INT_RDA); // RS232 OFF
after this I
enable_interrupts(global);
enable_interrupts(int_rda);
And then I have som ni the incom buffer?
It gose directly to
void serial_isr()
{
unsigned char RXBuffer;
crflag = 0x00;
RXBuffer = getc();
}
and there I have 2 more character.
that getc recive but after this the interrupts are totaly disable but I have set this them on as you can see.
Why is it like this?
The INTCON register is not as it should be becuse the INTF is 1 but if I reset this bit it still dosen't get anny new interrupts.
What To do?
Is it possibl to clear interrupts ?
So It dosen go in to serial_isr function?
If some one can help me i will be happy.....
___________________________
This message was ported from CCS's old forum
Original Post ID: 9837
R.J.Hamlett
Guest







Re: Interrupts problem with RS232
PostPosted: Fri Dec 06, 2002 11:49 am     Reply with quote

:=Hi
:=I have interrupts problem with RS232.
:=When i don't want anny more interrupts I
:= disable_interrupts(GLOBAL); // all interrupts OFF
:= disable_interrupts(INT_RDA); // RS232 OFF
:=after this I
:= enable_interrupts(global);
:= enable_interrupts(int_rda);
:=And then I have som ni the incom buffer?
:=It gose directly to
:=void serial_isr()
:={
:= unsigned char RXBuffer;
:= crflag = 0x00;
:= RXBuffer = getc();
:=}
:=and there I have 2 more character.
:=that getc recive but after this the interrupts are totaly disable but I have set this them on as you can see.
:=Why is it like this?
:=The INTCON register is not as it should be becuse the INTF is 1 but if I reset this bit it still dosen't get anny new interrupts.
:=What To do?
:=Is it possibl to clear interrupts ?
:=So It dosen go in to serial_isr function?
:=If some one can help me i will be happy.....

When you re-enable interrupts, if any data has been received by the UART, you will get the interrupt ISR being called. This is why you receive the garbage. However the problem here is if more than one character has been received, you will get the ISR, but the 'overrun error' flag will also be set in the UART. When you then return from the interrupt, with this error still set, no more characters will be received.
So you have a series of choices:
1) In the ISR, add code to check for the overrun error bit, and if it is set, clear the 'CREN' bit to clear this, and throw away the garbage. This is worth doing, since it will protect your code if this happens for any other reason.
2) Disable the UART, while you have the interrupts disabled. This is controlled by the SPEN bit, so you can code as:
#bit SPEN=0x18.7 //change the address to suit processor
#bit CREN=0x18.4

#define UART_ON() SPEN=true
#define UART_OFF() SPEN=false
#define CLEAR_OVERRUN() CREN=false; CREN=true

You can then disable the UART when required.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 9839
nilsener
Guest







Re: Interrupts problem with RS232
PostPosted: Fri Dec 06, 2002 12:41 pm     Reply with quote

Dear,

this is new for me, too. If I understand right, the overrun error bit will be set if the rx hardware buffer is full. Reading the datas via getc() clears the buffer but will not clear the overrun error bit ???
Can this be avoided by setting the error directive in the 'use rs232 statement, or is it ever necessary to clear the overrun error bit by myself if it is set to avoid that the system will hang ?

regards nilsener

:=:=Hi
:=:=I have interrupts problem with RS232.
:=:=When i don't want anny more interrupts I
:=:= disable_interrupts(GLOBAL); // all interrupts OFF
:=:= disable_interrupts(INT_RDA); // RS232 OFF
:=:=after this I
:=:= enable_interrupts(global);
:=:= enable_interrupts(int_rda);
:=:=And then I have som ni the incom buffer?
:=:=It gose directly to
:=:=void serial_isr()
:=:={
:=:= unsigned char RXBuffer;
:=:= crflag = 0x00;
:=:= RXBuffer = getc();
:=:=}
:=:=and there I have 2 more character.
:=:=that getc recive but after this the interrupts are totaly disable but I have set this them on as you can see.
:=:=Why is it like this?
:=:=The INTCON register is not as it should be becuse the INTF is 1 but if I reset this bit it still dosen't get anny new interrupts.
:=:=What To do?
:=:=Is it possibl to clear interrupts ?
:=:=So It dosen go in to serial_isr function?
:=:=If some one can help me i will be happy.....
:=
:=When you re-enable interrupts, if any data has been received by the UART, you will get the interrupt ISR being called. This is why you receive the garbage. However the problem here is if more than one character has been received, you will get the ISR, but the 'overrun error' flag will also be set in the UART. When you then return from the interrupt, with this error still set, no more characters will be received.
:=So you have a series of choices:
:=1) In the ISR, add code to check for the overrun error bit, and if it is set, clear the 'CREN' bit to clear this, and throw away the garbage. This is worth doing, since it will protect your code if this happens for any other reason.
:=2) Disable the UART, while you have the interrupts disabled. This is controlled by the SPEN bit, so you can code as:
:=#bit SPEN=0x18.7 //change the address to suit processor
:=#bit CREN=0x18.4
:=
:=#define UART_ON() SPEN=true
:=#define UART_OFF() SPEN=false
:=#define CLEAR_OVERRUN() CREN=false; CREN=true
:=
:=You can then disable the UART when required.
:=
:=Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 9840
Patrik �kerlind
Guest







Re: Interrupts problem with RS232
PostPosted: Fri Dec 06, 2002 12:42 pm     Reply with quote

:=:=Hi
:=:=I have interrupts problem with RS232.
:=:=When i don't want anny more interrupts I
:=:= disable_interrupts(GLOBAL); // all interrupts OFF
:=:= disable_interrupts(INT_RDA); // RS232 OFF
:=:=after this I
:=:= enable_interrupts(global);
:=:= enable_interrupts(int_rda);
:=:=And then I have som ni the incom buffer?
:=:=It gose directly to
:=:=void serial_isr()
:=:={
:=:= unsigned char RXBuffer;
:=:= crflag = 0x00;
:=:= RXBuffer = getc();
:=:=}
:=:=and there I have 2 more character.
:=:=that getc recive but after this the interrupts are totaly disable but I have set this them on as you can see.
:=:=Why is it like this?
:=:=The INTCON register is not as it should be becuse the INTF is 1 but if I reset this bit it still dosen't get anny new interrupts.
:=:=What To do?
:=:=Is it possibl to clear interrupts ?
:=:=So It dosen go in to serial_isr function?
:=:=If some one can help me i will be happy.....
:=
:=When you re-enable interrupts, if any data has been received by the UART, you will get the interrupt ISR being called. This is why you receive the garbage. However the problem here is if more than one character has been received, you will get the ISR, but the 'overrun error' flag will also be set in the UART. When you then return from the interrupt, with this error still set, no more characters will be received.
:=So you have a series of choices:
:=1) In the ISR, add code to check for the overrun error bit, and if it is set, clear the 'CREN' bit to clear this, and throw away the garbage. This is worth doing, since it will protect your code if this happens for any other reason.
:=2) Disable the UART, while you have the interrupts disabled. This is controlled by the SPEN bit, so you can code as:
:=#bit SPEN=0x18.7 //change the address to suit processor
:=#bit CREN=0x18.4
:=
:=#define UART_ON() SPEN=true
:=#define UART_OFF() SPEN=false
:=#define CLEAR_OVERRUN() CREN=false; CREN=true
:=
:=You can then disable the UART when required.
:=
:=Best Wishes

Thanks
The RCSTA register was really helpful why did I not se that...
Thanks one again.
___________________________
This message was ported from CCS's old forum
Original Post ID: 9841
R.J.Hamlett
Guest







Re: Interrupts problem with RS232
PostPosted: Fri Dec 06, 2002 2:17 pm     Reply with quote

:=Dear,
:=
:=this is new for me, too. If I understand right, the overrun error bit will be set if the rx hardware buffer is full.
Reading the datas via getc() clears the buffer but will not clear the overrun error bit ???
:=Can this be avoided by setting the error directive in the 'use rs232 statement, or is it ever necessary to clear the overrun error bit by myself if it is set to avoid that the system will hang ?
:=
:=regards nilsener
The bit will be set, if two characters are in the buffer, and not removed before a third character completes.
The overrun error remains set, when a character is then retrieved, to tell you that something is wrong.
Now it says in the data sheet, that in the event that this happens (and the OERR bit is set), then the character in the current receive shift register is lost. This appears to keep happening (ie. if the OERR bit is not cleared, the UART will not receive any more characters).
At this point, you can retrieve two characters from the receive buffers.
So ideally, you'd check for the OERR bit on entry to the receive routine, and if it is set, retrieve two characters, and then reset the bit. However provided you accept that since characters have allready been lost, the data in the buffer is allready garbage, you can just reset the UART to clear the error.
Now this is not normally a problem, because of the long time intervals involved (at 9600bps, you have to 'not service' the receive interrupt, or poll the port for just over 2mSec, to cause this). However in the specific case given, of disabling the port, this has to be dealt with.

Best Wishes

:=:=:=Hi
:=:=:=I have interrupts problem with RS232.
:=:=:=When i don't want anny more interrupts I
:=:=:= disable_interrupts(GLOBAL); // all interrupts OFF
:=:=:= disable_interrupts(INT_RDA); // RS232 OFF
:=:=:=after this I
:=:=:= enable_interrupts(global);
:=:=:= enable_interrupts(int_rda);
:=:=:=And then I have som ni the incom buffer?
:=:=:=It gose directly to
:=:=:=void serial_isr()
:=:=:={
:=:=:= unsigned char RXBuffer;
:=:=:= crflag = 0x00;
:=:=:= RXBuffer = getc();
:=:=:=}
:=:=:=and there I have 2 more character.
:=:=:=that getc recive but after this the interrupts are totaly disable but I have set this them on as you can see.
:=:=:=Why is it like this?
:=:=:=The INTCON register is not as it should be becuse the INTF is 1 but if I reset this bit it still dosen't get anny new interrupts.
:=:=:=What To do?
:=:=:=Is it possibl to clear interrupts ?
:=:=:=So It dosen go in to serial_isr function?
:=:=:=If some one can help me i will be happy.....
:=:=
:=:=When you re-enable interrupts, if any data has been received by the UART, you will get the interrupt ISR being called. This is why you receive the garbage. However the problem here is if more than one character has been received, you will get the ISR, but the 'overrun error' flag will also be set in the UART. When you then return from the interrupt, with this error still set, no more characters will be received.
:=:=So you have a series of choices:
:=:=1) In the ISR, add code to check for the overrun error bit, and if it is set, clear the 'CREN' bit to clear this, and throw away the garbage. This is worth doing, since it will protect your code if this happens for any other reason.
:=:=2) Disable the UART, while you have the interrupts disabled. This is controlled by the SPEN bit, so you can code as:
:=:=#bit SPEN=0x18.7 //change the address to suit processor
:=:=#bit CREN=0x18.4
:=:=
:=:=#define UART_ON() SPEN=true
:=:=#define UART_OFF() SPEN=false
:=:=#define CLEAR_OVERRUN() CREN=false; CREN=true
:=:=
:=:=You can then disable the UART when required.
:=:=
:=:=Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 9842
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