Programming advice when using interrupts

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
Zane
Flowcode v5 User
Posts: 199
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Contact:

Programming advice when using interrupts

Post by Zane »

Hi,

I have a program i am writing with code present in the main loop. I am also using the CAL UART component. I have an interrupt routine that is triggered by data being received by the UART. The interrupt routine processes the incoming data. Once this is done a status needs to be transmitted from the UART immediately. The host requires a response in under a 1mS to prevent faults being generated.

What i wanted to know is what is the best way of doing this. I am not sure if i am right but you cannot call the send maco for the CAL UART from inside the interrupt routine without errors being generated. Waiting until you return to the main loop and sending from there would lead to problems in regards to too much of a time delay as you cannot guarantee what part of the main loop the interrupt was triggered. One way i thought would be to use a "C" code icon and manually send the data to the UART from there from within the interrupt routine. Does anyone have any other ideas of doing this efficiently.

Thanks in advance :D

User avatar
Benj
Matrix Staff
Posts: 15014
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Programming advice when using interrupts

Post by Benj »

Hi Zane,
I am not sure if i am right but you cannot call the send maco for the CAL UART from inside the interrupt routine without errors being generated.
This should be possible, what errors are you getting?

Zane
Flowcode v5 User
Posts: 199
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Contact:

Re: Programming advice when using interrupts

Post by Zane »

Hi Ben,

Thanks for your reply. If i have a macro call for a send for the CAL UART in the main loop and also any other macro that i have created there are no problems. If i also put in a call for the CAL UART from any macro that is called via an interrupt i get the following message when there is the same call present also in the main loop.
Capture.JPG
Capture.JPG (14.31 KiB) Viewed 1838 times
Does this cause any problems?

User avatar
Benj
Matrix Staff
Posts: 15014
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Programming advice when using interrupts

Post by Benj »

Hi Zane,

This is a warning and not an error. It basically states that the transmit function exists inside the main loop and again inside the interrupt so the code has been duplicated.

If there is a chance that the main loop can be transmitting and the interrupt can kick in then this is certainly a problem you want to try and avoid or data could be sent out of order etc.

If you have done all transmitting in main before you enable the interrupt then this is not a problem and you can ignore the warning.

Zane
Flowcode v5 User
Posts: 199
Joined: Thu Sep 10, 2009 10:57 pm
Location: New Zealand
Contact:

Re: Programming advice when using interrupts

Post by Zane »

Hi Ben,

Thanks for that explanation, that clarifies the issue and i can now work around that. Thanks for your help :D

Post Reply