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.

MSP430F5659: Prioritizing UART and USB Interrupts for Modbus Protocol Handling on MSP430

Part Number: MSP430F5659

Hello TI Community,

I am currently working on a project where I'm utilizing both UART and USB interfaces on an MSP430 microcontroller to handle data using the Modbus protocol. To efficiently manage data reception and transmission, I am using a single transmit and receive buffer. However, I am encountering challenges in prioritizing interrupts between UART and USB to ensure reliable data handling.

My objective is to prioritize interrupts based on the first interrupt received. If I receive an interrupt from UART, I want to handle data reception and service the data according to the Modbus function code (read or write). After servicing the data, I intend to wait until the next interrupt from either UART or USB.

Could you please provide guidance or a suggested approach on how to implement this prioritization reliably and efficiently on the MSP430 microcontroller?

Thank you for your assistance.

Best regards,

Baseer

  • You could always do it all in the interrupt handler, but what do you want to happen if you get a USB interrupt while servicing the UART interrupt?

  • Baseer,

    MSP430 doesn't allow for interrupt priority changes and is fixed. So depending on the USCI you chose it will have either a lower or higher priority than the USB interrupts. Now, MSP430 doesn't service interrupt when in another interrupt (nesting) by default. (Not recommended to do nesting interrupts on MSP430 either unless you are really savvy.) So that means, you will only get a collision if you have both the UARt and USB interrupt happen at the same time, or if you get the higher priority interrupt for a second time while still servicing that same interrupt. If you keep your interrupts really short, and do most of your work in the main loop, you will minimize these cases. 

    That being said, to handle the cases you do catch, you can always d some "critical code sections" where you disable interrupts and manually check the interrupts flags for lower priority interrupt in order to service manually. Just take care to also handle the higher priority interrupt after as well, as reading the interrupt register clears the highest pending interrupt. 

  • In that case what I ideally want is to service the UART interrupt first. And would hold the USB interrupt until current interrupt is being serviced. But I am not sure how can I manage that.

  • Jace,

    Can you  guide me how can I disable interrupts and manually check the interrupts flags for lower priority interrupt in order to service manually. 

  • When you get a USB interrupt, check to see if a UART interrupt is pending, and if so, immediately exit the interrupt.

    But this can only happen if both interrupts happen at the same time.

  • Alternatively, use a USCI that has a higher priority than USB interrupts. I believe USCIA0 has the highest priority, but double check the datasheet. (Highest priority interrupt is the lower number.)

**Attention** This is a public forum