Page 1 of 1

RS232 Interupts

Posted: Sat Feb 09, 2013 2:56 am
by jethronull
The help file for creating interupts suggests that a custom interupt must be created for PIC uarts using:
Enable code:
intcon.PEIE = 1; // Enable peripheral interrupts
intcon.GIE = 1; // Enable global interrupts
pie1.RCIE = 1; // Enable USART receive interrupts

Disable code:
pie1.RCIE = 0; // Disable USART receive interrupts

Handler code:
if (pir1 & (1 << RCIF))
{
FCM_%n(); // call selected macro
clear_bit(pir1, RCIF); // clear interrupt
}
But this code does not seem to be a good match for my processor (18F87K22). Most of these registers are different. Can someone help me work out what is required for this processor?

TIA, JethroNull

Re: RS232 Interupts

Posted: Sat Feb 09, 2013 1:44 pm
by kersing
This processor has 2 EUART modules. This results in two sets of bits to enable/disable/check the interrupts.

For UART1 change RCIE to RC1IE and RCIF to RC1IF.
For UART2 change RCIE to RC2IE, pie1 to pie3, RCIF to RC2IF and pir1 to pir3.

RS232 Interupts in dspic

Posted: Tue May 07, 2013 11:40 pm
by r_romeo
I am having a similar problem with dsPIC30f4012 for end of transmitting interrupt

enable code :

IEC0bits.U1TXIE = 1;

handler code:

//if (IFS0bits.U1TXIF=1) (is this the same than next line?)
if (IFS0 & (1 <<U1TXIF))
{
FCM_UARTTX_INT();// call selected macro
IFS0bitsU1TXIF = 0;
}

the error generated:

ID_01_07.c:4438: error: syntax error before 'if'
ID_01_07.c:4441: warning: type defaults to 'int' in declaration of 'IFS0bitsU1TXIF'
ID_01_07.c:4441: warning: data definition has no type or storage class
ID_01_07.c:4442: error: syntax error before '}' token

Looks I have to declare IFS0bitsU1TXIF before but should'n be declared in flowcode??

Any idea??

Re: RS232 Interupts

Posted: Wed May 08, 2013 11:08 am
by Benj
Hello,

This should work.

enable code:

Code: Select all

IEC0bits.U1TXIE = 1;
handler code:

Code: Select all

if (IFS0bits.U1TXIF=1)
{
  FCM_UARTTX_INT();// call selected macro
  IFS0bits.U1TXIF = 0;
}
Your main issue was you were missing the . after IFS0bits on the last line of the handler code.

Re: RS232 Interupts

Posted: Wed May 08, 2013 6:48 pm
by r_romeo
Hi Ben, Thanks for the tip, but still doesn not compile.
Here is a test file I did to probe it
servomotor test.fcf_pic16
(13 KiB) Downloaded 446 times
I get this message from compiler

servomotor test.c: At top level:
servomotor test.c:1235: error: redefinition of '_T2Interrupt'
servomotor test.c:1159: error: previous definition of '_T2Interrupt' was here
servomotor test.c:1245: error: syntax error before 'if'

Re: RS232 Interupts

Posted: Thu May 09, 2013 10:10 am
by Benj
Hello,

The servo component uses Timers 2 and 3 as part of it's functionality on 16-bit PICs. Can you use another timer instead e.g. 1, 4 or 5?

Re: RS232 Interupts

Posted: Thu May 09, 2013 12:31 pm
by r_romeo
Hi Ben,
Where is the conflict? the Uart block uses also timers?

I did an example without the timer and servo, still not working

Here is the file with no servo block
uart tx test.fcf_pic16
(11 KiB) Downloaded 430 times
I get the same error than before
Is there a variable I need to define before?
In an example of activating a timer with code that is working, in the handle code
there is a void part that is not in my example . Is this maybe the cause of the problem?

Code: Select all

//Handler code for [TMR2]
	void _ISR _T2Interrupt(void)
	{
		IFS0bits.T2IF = 0;
	                FCM_REAL_TIME_2();
	}

Re: RS232 Interupts, Ani idea of how can this be solved

Posted: Thu Jun 13, 2013 9:13 am
by r_romeo
Sorry I've Been Away in a job for some weeks,

Any idea of how can this be solved?
definitely the code I attached should work, no servo or timers

I am really lost in this area of C code

Thanks

Re: RS232 Interupts

Posted: Thu Jun 13, 2013 11:54 am
by Benj
Hello,

Youur UART TX handler code should look like this.

Code: Select all

void _ISR _TXInterrupt(void)
{
if (IFS0bits.U1TXIF=1)
{
  FCM_dummy();// call selected macro
  IFS0bits.U1TXIF = 0;
}
}
or maybe like this if you want slightly less latency.

Code: Select all

void _ISR _TXInterrupt(void)
{
  FCM_dummy();// call selected macro
  IFS0bits.U1TXIF = 0;
}
Once I made this change the program is now compiling correctly for me, no mention of timer 2 in the C code.

Re: RS232 Interupts

Posted: Thu Jun 13, 2013 3:01 pm
by r_romeo
That is perfect, thanks !!

Re: RS232 Interupts, compiling but not working.

Posted: Tue Jul 09, 2013 2:50 pm
by r_romeo
Sorry for the delay but I was trying to solve another problems and
this particular one, Basically the code provided by Ben is compiling
but in the real world the interrupt is not been produced, (led ON)
no way Ican make it work .
The only clue I think would be is that in the message file says
rx.c: In function '_TXInterrupt':
rx.c:445: warning: PSV model not specified for '_TXInterrupt';
assuming 'auto_psv' this may affect latency
rx.c: At top level:
rx.c:448: warning: Invalid interrupt vector names for device '30F4012' are:
_TXInterrupt
the which brings me to other question that could help for other custom made interrupts :
How do we provide the name for the Void type ???
Is this important ??

just in case It does not have to do with this, here are the code I use for RX and TX
tx.fcf_pic16
(9 KiB) Downloaded 384 times
rx.fcf_pic16
(11 KiB) Downloaded 392 times
thanks!

Re: RS232 Interupts

Posted: Sat Jul 27, 2013 9:47 am
by r_romeo
Hi Guys
Does anyone have two dsPic microcontrollers connected with USART that can test the files I provided?
Just to check out what is missing or wrong with the custom interrupt

Thanks

Re: RS232 Interupts

Posted: Mon Jul 29, 2013 9:23 am
by Benj
Hello,

Looking at the datasheets it seems the RX and TX interrupt vector should instead look like this.

void _ISR _U1TXInterrupt(void)

Can you test the RX interrupt to confirm this is working before you start on the TX interrupt?

Re: RS232 Interupts

Posted: Wed Jul 31, 2013 8:12 am
by r_romeo
Hi Ben
thank for your help, but is not working.
I am using the custom code for RX interrupt


Enable code :

Code: Select all

IEC0bits.U1RXIE = 1;

Handler code:

Code: Select all

void _ISR _U1RXInterrupt(void)
{
if (IFS0bits.U1RXIF=1)
{
  FCM_dummy();// call selected macro
  IFS0bits.U1RXIF = 0;
}
} 
Also I have tried

Code: Select all

void _ISR _RXInterrupt(void)
I have not found the psv model reference in the web.
here are the latest code I am using
rx.fcf_pic16
(11 KiB) Downloaded 290 times
tx.fcf_pic16
(11.5 KiB) Downloaded 328 times
I double check both speeds and the RS232 signal that is arriving

:?

Re: RS232 Interupts

Posted: Fri Aug 02, 2013 9:32 am
by r_romeo
Ben ,

I have a big question: where can I find information about the interrupt vectors? Is that a compiler's situation?
dsPics have different vector names? I saw other questions about UART interrupts and seems to be answered , but those answers applied to my dspic does not seems to work.
By other way, as you can see, I have the alternative UART port enabled, but would not make sense if this was the reason of the problem.

Thank you for your support!!

Re: RS232 Interupts

Posted: Fri Aug 02, 2013 1:24 pm
by Benj
Hello,

The compiler used in Flowcode for dsPIC is the C30 compiler from Microchip. You should be able to look at the device header file located in this folder.

C:\Program Files (x86)\Flowcode(dsPIC)\v5\Tools\C_tools\support\dsPIC30F\h

There should also be C30 manuals available from Microchip which should help with the issue and lists all the generic interrupt vectors.

Let me know how your getting on.