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.

how to use 2UART & 1I2C same time & write single interrupt to handle both peripherals(UART & I2C) MSP430F2617

Other Parts Discussed in Thread: MSP430F2617

Dear All,

i had an existing solution for street Light we are using MSP430F2617.

In our existing Street Light Controller , some modifications are necessary to meet the upcoming project specification. So this MCU  needs to communication with 2UART & 1I2C.

Initially we are using 1 UART & 1I2C peripherals only.

Now with the new specifications 2UART & 1 I2C communication necessary.

Existing MCU MSP430F2617 as per datasheet 2UART & 2I2C interface is provided ,but its interrupt vector is same.

So I request you that please provide the help to use the 2UART & 1I2C same time.

How to write single interrupt to handle both peripherals(UART & I2C).

Please do the needful.

regards,

utpal

  • Hi Utpal,

    you can check for the pending flags inside the ISRs:

    #pragma vector = USCIAB0TX_VECTOR
    __interrupt void USCIAB0TX_ISR
    {
      if( IFG2 & UCA0TXIFG )
      {
        // Do something for USCI_A0 UART TX
      }
      else if( IFG2 & UCB0TXIFG )
      {
        // Do something for USCI_B0 I2C TX
      }
    }
    
    #pragma vector = USCIAB0RX_VECTOR
    __interrupt void USCIAB0RX_ISR
    {
      if( IFG2 & UCA0RXIFG )
      {
        // Do something for USCI_A0 UART RX
      }
      else if( IFG2 & UCB0RXIFG )
      {
        // Do something for USCI_B0 I2C RX
      }
    }
    
    #pragma vector = USCIAB1TX_VECTOR
    __interrupt void USCIAB1TX_ISR
    {
      if( UC1IFG & UCA1TXIFG )
      {
        // Do something for USCI_A1 UART TX
      }
      else if( UC1IFG & UCB1TXIFG )
      {
        // Do something for USCI_B1 I2C TX
      }
    }
    
    #pragma vector = USCIAB1RX_VECTOR
    __interrupt void USCIAB1RX_ISR
    {
      if( UC1IFG & UCA1RXIFG )
      {
        // Do something for USCI_A1 UART RX
      }
      else if( UC1IFG & UCB1RXIFG )
      {
        // Do something for USCI_B1 I2C RX
      }
    }

    Dennis

  • Hi,
    Thanks for your quick response .
    Please help me to resolve my doubt.

    #pragma vector = USCIAB0TX_VECTOR
    __interrupt void USCIAB0TX_ISR
    {
    if( IFG2 & UCA0TXIFG )
    {
    // Do something for USCI_A0 UART TX
    }
    else if( IFG2 & UCB0TXIFG )
    {
    // Do something for USCI_B0 I2C TX
    }
    }

    In above code what will happens if I2C connected to UCB0TXIFG & UART connected to UCA0TXIFG initialize the sending of data at the same time.
    Is there any possibility that transmission data will get missed.as UART operate on baud rate (timings) & if its interrupt is pending due to I2C work.
    Please clarify.

    Regards,
    utpal
  • The other interrupt flag stays set and will be serviced afterwards. Of course the interrrupt service routine has to be short enough to handle the other interrupt before another interrupt is generated for the source you did not even finish, otherwise you will loose interrrupt requests.

    You could change the code to the following as well:

    #pragma vector = USCIAB0TX_VECTOR
    __interrupt void USCIAB0TX_ISR
    {
      if( IFG2 & UCA0TXIFG )
      {
        // Do something for USCI_A0 UART TX
      }
      
      if( IFG2 & UCB0TXIFG )
      {
        // Do something for USCI_B0 I2C TX
      }
    }

    In this case both sources are checked in one interrupt service routine call. This will shorten the time if both flags are set, but the ISR takes longer if they are not.

    Dennis

**Attention** This is a public forum