cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F303 HAL ISR being called twice

BČern.1
Associate

Hello!

I am writing a program in which I am controlling a ST32F303 MCUs DAC1 and DAC2, thru a USB port, via LabView. The LabView part sends a data string containing the following "1,4095". The one implicates which DAC I am trying to control(in this case the first one), while the second part indicates the value of the DAC it has to be set to. The DAC value goes from 0-4095(which is 0V - 3.3V on the output when it has no load).

The problem I have encountered is that when the interrupt fires on receiving new data the ISR gets executed twice for no apparent reason. This causes my program to be slower than expected and causing the DAC to setting the wrong values.

I am new to ST32 and ARMs in general so I'm posting the entire code below for better understanding. Thanks in advance for helping out.

Regards

5 REPLIES 5
gbm
Lead III

Blocking call to UART_Transmit inside of UART interrupt service routine does not seem to be a good design idea.

Things will fire twice, or continuously, if the cause what not properly cleared.

There's also the fact that the processor is pipelined, and has deferred writes via the write buffers.

The tail-chaining decisions can be made before the interrupt service/clearance propogates from the peripheral on a slower bus vs the NVIC tightly coupled to the core.

Always qualify the source of the interrupt, don't respond blindly.

An interrupt may enter with one, or many things signalling. Things may also occur in the time domain as the code executes.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Any variables changed under interrupt/callback, and used elsewhere need to be volatile.

You can't use auto/local variables in callbacks, or elsewhere, for DMA or IT buffering they are on the stack and disappear as the scope collapses.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

"Any variables changed under interrupt/callback, and used elsewhere need to be volatile."

Not true. Rather "variables used for communication between pieces of code running at different processor priority levels". A non-volatile flag may be used for communication between two ISRs of the same priority.

Depends on the complexity of the interaction, but it's relatively cheap, and recommended for changes out side of normal, linear, code flow.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..