This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F5529: UART receive interrupt nested in timer A ISR

Part Number: MSP430F5529

Hi all,

I am working on a project where i want to read the data of a sensor at a rate of 90 - 100 Hz. For this sensor-read i wrote a function which consists of a transaction over UART where a command gets send and a response is send back and is processed. The respons of the sensor is triggered by the UART receive ISR which receives the bytes and pushes them into ring buffer. Back in the function, the data gets processed and is then returned to the main code.

Now, this functions for reading the data runs perfectly when i run in the main in a while(1) loop. But the moment i run this function within the timer ISR, the UART receive ISR doesn't get triggered at every byte. While the function expects 83 Bytes it goes into the ISR only once. I checked the priority and the UART (USCI_A0) has a higher priority then the timer (timer_A), so that can't be the problem.

Is this because MSP430 doesn't allow nesting of ISR's? or is it because triggering the UART ISR multiple times in the timer ISR isn't possible? and how could i make this work without using flagbits to trigger the data-read in my main code?

Cheers,

Caspar

  • Hi Caspar,

    My initial inquiry is why you are staying in the Timer ISR for an extended amount of time. Is the code executed in that ISR able to be pulled out so that the ISR can remain as short as possible, such as setting a flag for the Timer code to be executed? This way the UART ISR will not be kept from firing.

    To answer your initial question, nested interrupts are not enabled by default. When an ISR is triggered the GIE bit is cleared thus disabling any other interrupts from firing. If you really want to work with nested interrupts then you will have to enable to the GIE bit inside of the Timer ISR in order to allow for the UART interrupt to be triggered.

    Best regards,

    Matt

  • Hi Matt,

    Thank you for replying.

    yes, i tried working with flag bits to trigger a reading of my sensor in the main code. However, this data needs to read consistently on the same frequency and in my main code i meant to implement a state machine to decide what code needs to be executed depending on the readings of the sensors.

    I already tried setting the GIE bit in the ISR timer by executing the __enable_interrupt() function. if i'm not mistaken this sets the GIE bit. But now when the timer ISR gets executed, my program crashes. So my guess is that it doesn't work when you try to trigger the same ISR multiple times within the timer ISR.

  • Nesting interrupts is hazardous. The MSP430 effectively only has two interrupt priorities: GIE=0 or 1. Enabling GIE in an ISR enables Any interrupt -- including your own. Most ISRs aren't written to handle this (it's not easy).

    It seems to me that your sampling rate is determined by the moment when you send the command to the sensor. You could do that in the ISR, then let the bytes come back while you're doing other things.

  • Caspar,

    As Bruce suggested it is not recommended to write code on the MSP430 where nested ISRs are used. The code flow recommended above by Bruce would likely be the best way to move forward.

    Best regards,

    Matt

**Attention** This is a public forum