|
|
View previous topic :: View next topic |
Author |
Message |
g-netix
Joined: 19 Aug 2012 Posts: 19
|
problem with RS232 interrupt |
Posted: Wed Aug 07, 2013 6:41 am |
|
|
Hi!
I'm using a PIC18F2420 and PCW v4.132. I use an external integrated 24MHz osc without X4 PLL.
I work with the UART @ 250 kbaud and I need to detect 2 consecutive framing error to synchronize a signal.
I've added "errors" in the #USE RS232 statement, I know that Framing Error is the bit 2 of RS232_ERRORS, but now I want it to do an interrupt and use it to reset a variable.
It seems that PCW does what it has to do (clearing the flag, etc) but I need an access to this interrupt and don't know how to proceed and don't want to use ASM.
Thank you for your help |
|
|
oxo
Joined: 13 Nov 2012 Posts: 219 Location: France
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19541
|
|
Posted: Wed Aug 07, 2013 7:41 am |
|
|
I think you may be misunderstanding the hardware.
Read below the '.................'
In general, everything can be done separately or together....
If an interrupt is enabled, and global interrupts are enabled, then the handler will be called, when the flag is set. If you don't want the handler to be called, then just disable the interrupt (the interrupt flag will still be set). You can read the flag with the command 'interrupt_active'. So:
interrupt_active(INT_RDA) will go 'true', when the interrupt is set.
Either in the handler or in your main code (if polling the interrupt), the flag can't be cleared, till the character is read. Once the character has been read, you can clear it manually, with 'clear_interrupts'. If you are using an interrupt handler, and don't want the compiler to clear the interrupt itself, then add the keyword 'NOCLEAR' to the interrupt definition. So:
Code: |
#INT_RDA NOCLEAR
void rx_interrupt(void)
{
//Now the compiler leaves it up to _you_ to clear the interrupt
}
|
If you use the keyword 'ERRORS' in the RS232 definition, then the compiler will automatically clear UART error conditions when the character is read, and copy the errors to 'RS232_ERRORS'. If you leave this keywords out, then this automatic behaviour is omitted, and you have to clear the errors yourself. So:
Code: |
#bit OERR=getenv("BIT:OERR")
if (OERR) {
//overrun error is set
//You now have to disable the UART, and re-enable it
set_uart_speed(DISABLED);
set_uart_speed(250000);
//etc. etc..
|
It is one of the 'powers' of CCS, that while a lot of things default to automatic operations, making general coding simpler, just about all can be turned off if required.
........................
However, from your description, you don't need to 'access this interrupt'. There is no separate 'framing error' interrupt on this chip (there is on chips like the DsPIC's). All you need to do, is have a standard INT_RDA handler, with something like:
Code: |
#INT_RDA
void rx(void)
{
static int1 last_error=FALSE;
int8 dummy;
dummy=getc();
if (BIT_TEST(RS232_ERRORS,2)
{
if (last_error==TRUE)
{ //Here there have been two successive framing errors
//Do what you want
last_error=FALSE;
}
else
last_error=TRUE;
}
else
{
last_error=FALSE;
//Here no framing error, so do what you want with the data
//store 'dummy' how you want.
//You can obviously add handling for other errors if required.
}
}
|
When chips do have a separate framing error, CCS offers separate handlers for them....
Best Wishes |
|
|
g-netix
Joined: 19 Aug 2012 Posts: 19
|
|
Posted: Wed Aug 07, 2013 8:09 am |
|
|
Oh yeah thank you so much! it seems to work well!
I bought CCS because I found it simpler than MPLAB C18, but I didn't know its capability to enable or disable some automatic functions...
Thanks to you I think the problem is resolved ;) |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Wed Aug 07, 2013 2:40 pm |
|
|
g-netix wrote: |
I bought CCS because I found it simpler than MPLAB C18, but I didn't know its capability to enable or disable some automatic functions...
|
This is the tradeoff between C18 (now XC8 which is supposedly better than C18) and CCS PIC-C.
PIC-C has a lot of the things that are hard done for you. If you had to write things like ISR routines from scratch in CCS, they'd end up looking a lot like C18.
PIC-C typically saves a lot of time.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|
|
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
|