RS232 Interupts

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
jethronull
Posts: 30
Joined: Tue Dec 04, 2012 4:03 am
Has thanked: 1 time
Contact:

RS232 Interupts

Post 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
Jon/JethroNull

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: RS232 Interupts

Post 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.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

RS232 Interupts in dspic

Post 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??

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 Interupts

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

r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

Re: RS232 Interupts

Post 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 346 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'

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 Interupts

Post 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?

r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

Re: RS232 Interupts

Post 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 374 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();
	}

r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

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

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 Interupts

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

r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

Re: RS232 Interupts

Post by r_romeo »

That is perfect, thanks !!

r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

Re: RS232 Interupts, compiling but not working.

Post 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 316 times
rx.fcf_pic16
(11 KiB) Downloaded 314 times
thanks!

r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

Re: RS232 Interupts

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 Interupts

Post 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?

r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

Re: RS232 Interupts

Post 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 236 times
tx.fcf_pic16
(11.5 KiB) Downloaded 233 times
I double check both speeds and the RS232 signal that is arriving

:?

r_romeo
Posts: 54
Joined: Wed Nov 02, 2011 3:57 pm
Has thanked: 14 times
Been thanked: 3 times
Contact:

Re: RS232 Interupts

Post 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!!

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 Interupts

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

Post Reply