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.

MSP430G2553: Interfacing BM180 on I2C lines

Part Number: MSP430G2553

Hello,

I was trying to interface a BM180 module with MSP430 value line launchpad which is running on MSP430G2553 chip. The BM180 module has the pull ups installed so I did not use additional pullups. Since BM180 powers up between 1.8V to 3.6V, I connected the Vcc of launchpad to Vcc of BM180. Connected P1.6 of launchpad to SCL of BM180 and P1.7 to SDA of BM180. I used the code examples from msp430g2xx3_uscib0_i2c_8.c and msp430g2xx3_uscib0_i2c_10.c and combined them to write following code. My first step is to get an interrupt at Rx and check the buffer in debugger (if that happens, rest is easier to achieve). The below code does not work and when I debug, I see that I get a Tx interrupt only once and then it always stays in TransmitI2C(). This means the stop bit wasn't sent and then I do not get Rx interrupt. I am stuck here for past two days. Can you please help me how I could move on? Please point out at any obvious mistakes that could be doing.

#include <msp430.h>

int RXByteCtr, RPT_Flag = 0;                // enables repeated start when 1
volatile unsigned char RxBuffer[64];       // Allocate 128 byte of RAM
unsigned char TxBuffer[64];
unsigned char *PRxData;                     // Pointer to RX data
unsigned char TXByteCtr, RX = 0;
unsigned char *PTxData;                     // Pointer to TX data
unsigned char TXByteCtr;


int I2C_Init(int slaveaddr)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  P1SEL |= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0
  P1SEL2|= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0
  UCB0CTL1 |= UCSWRST;                      // Enable SW reset
  UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;     // I2C Master, synchronous mode
  UCB0CTL1 = UCSSEL_2 + UCSWRST;            // Use SMCLK, keep SW reset
  UCB0BR0 = 12;                             // fSCL = SMCLK/12 = ~100kHz
  UCB0BR1 = 0;
  UCB0I2CSA = slaveaddr;                    // Slave Address is 048h
  UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation
  IE2 |= UCB0TXIE;                          // Enable TX interrupt
  IE2 |= UCB0RXIE;                          // Enable RX interrupt
  return 0;
}

int TransmitI2C(unsigned char *TxData, int TxData_size)
{
  PTxData = (unsigned char *)TxData;      // TX array start address
  TXByteCtr = TxData_size;                // Load TX byte counter
  while (UCB0CTL1 & UCTXSTP);             // Ensure stop condition got sent
  UCB0CTL1 |= UCTR + UCTXSTT;             // I2C TX, start condition
  __bis_SR_register(CPUOFF + GIE);        // Enter LPM0 w/ interrupts
                                          // Remain in LPM0 until all data
                                          // is TX'd
  return 0;
}

int ReceiveI2C(int RxData_size)
{

  PRxData = (unsigned char *)RxBuffer;    // Start of RX buffer
  RXByteCtr = RxData_size;                // Load RX byte counter
  while (UCB0CTL1 & UCTXSTP);             // Ensure stop condition got sent
UCB0CTL1 &= ~UCTR;                      // Set to slave mode UCB0CTL1 |= UCTXSTT; // I2C start condition __bis_SR_register(CPUOFF + GIE); // Enter LPM0 w/ interrupts // Remain in LPM0 until all data // is RX'd __no_operation(); // Set breakpoint >>here<< and return 0; } int main() { I2C_Init(0x77); TxBuffer[0] = 0xAA; TransmitI2C((unsigned char *)TxBuffer, 1); ReceiveI2C(2); TxBuffer[0] = 0xAC; TransmitI2C((unsigned char *)TxBuffer, 1); ReceiveI2C(2); TxBuffer[0] = 0xAE; TransmitI2C((unsigned char *)TxBuffer, 1); ReceiveI2C(2); TxBuffer[0] = 0xB0; TransmitI2C((unsigned char *)TxBuffer, 1); ReceiveI2C(2); TxBuffer[0] = 0xB2; TransmitI2C((unsigned char *)TxBuffer, 1); ReceiveI2C(2); TxBuffer[0] = 0xB4; TransmitI2C((unsigned char *)TxBuffer, 1); ReceiveI2C(2); TxBuffer[0] = 0xB6; TransmitI2C((unsigned char *)TxBuffer, 1); ReceiveI2C(2); TxBuffer[0] = 0xB8; TransmitI2C((unsigned char *)TxBuffer, 1); ReceiveI2C(2); TxBuffer[0] = 0xBA; TransmitI2C((unsigned char *)TxBuffer, 1); ReceiveI2C(2); TxBuffer[0] = 0xBC; TransmitI2C((unsigned char *)TxBuffer, 1); ReceiveI2C(2); TxBuffer[0] = 0xBE; TransmitI2C((unsigned char *)TxBuffer, 1); ReceiveI2C(2); return 0; } //------------------------------------------------------------------------------ // The USCIAB0TX_ISR is structured such that it can be used to transmit any // number of bytes by pre-loading TXByteCtr with the byte count. Also, TXData // points to the next byte to transmit. //------------------------------------------------------------------------------ #pragma vector = USCIAB0TX_VECTOR __interrupt void USCIAB0TX_ISR(void) { if (TXByteCtr) // Check TX byte counter { UCB0TXBUF = *PTxData++; // Load TX buffer TXByteCtr--; // Decrement TX byte counter } else { UCB0CTL1 |= UCTXSTP; // I2C stop condition IFG2 &= ~UCB0TXIFG; // Clear USCI_B0 TX int flag __bic_SR_register_on_exit(CPUOFF); // Exit LPM0 } } //------------------------------------------------------------------------------- // The USCI_B0 data ISR is used to move received data from the I2C slave // to the MSP430 memory. It is structured such that it can be used to receive // any 2+ number of bytes by pre-loading RXByteCtr with the byte count. //------------------------------------------------------------------------------- #pragma vector = USCIAB0RX_VECTOR __interrupt void USCIAB0RX_ISR(void) { RXByteCtr--; // Decrement RX byte counter if (RXByteCtr) { *PRxData++ = UCB0RXBUF; // Move RX data to address PRxData if (RXByteCtr == 1) // Only one byte left? UCB0CTL1 |= UCTXSTP; // Generate I2C stop condition } else { *PRxData = UCB0RXBUF; // Move final RX data to PRxData __bic_SR_register_on_exit(CPUOFF); // Exit LPM0 } }

  • Hello Shankar,

    Here is a link to an application note that describes how to debug various serial communication issues. I2C is covered starting on page 10. Please let me know if you have any questions regarding the document or if it doesn't help solve your issue.

    Regards,

    Matthew

  • Well, First issue was I fell prey to the name of the interrupt that was absolutely misleading. USCIAB0RX_VECTOR does not capture an i2C interrupt. In fact Both I2C Tx and Rx share the same interrupt USCIAB0TX_VECTOR. So I had to change one of my ISR shown above to handle both Tx and Rx This was demonstrated in the file msp430g2xx3_uscib0_i2c_12.c. I deleted the ISR USCIAB0RX_ISR which is useless in this context. After this, I could see something on my sclk lines on CRO. I still did not get the communication going. Right now debugging the same. Any other place where I could look? By the way I verified that IFG is set of Tx interrupt and my UCB0TXBUF is properly written when I first arrive at the interrupt. The issue is for some strange reason, the interrupt does not seem to hit the second time and it is always stuck in Transmit because it is only the second time, we clear the IFG flag and send the stop bit.
  • Hello Shankar,

    The best methods for debugging I can give you are the ones outlined in the application note:

    Verify the pullup resistances and slave address value using the slave device data sheet

    Check all peripheral initialization, including:

    • Physical pin selection (SDA and SCL)

    • Communication register settings

    • Enabling of interrupts (both local and global)

    • When developing SMBUS communication based on I2C, see SMBUS Design Using MSP430 Design Guide.

    Use the tools available (for example, IDE debugger, logic analyzer, and oscilloscope) to prove that both ends of the bus are adhering to the I2C software protocol.

    Review the MSP430 device errata sheet for I2C errata that could be involved

    Additionally, referencing other I2C example codes found in the resource explorer may be helpful.

    Regards,

    Matthew

  • Hello Mathew,

    I did refer to the document and am going by that for sure. Physical pin selection is OK, I have debugged register settings and I even mentioned the debugging steps in last post. I also see that interrupts are enabled and am seeing an interrupt (transmission). After this I don't know why Tx interrupt does not occur again even when IFG flag is not cleared.

    I have refereed to all the examples and I have used the ISRs from examples. Slave address is Ok as I have verified other working libraries (Adafruit for arduino) about the correctness of the slave address.

    Regards,

    Shankar

  • Hello Shankar,

    I've attached another code example. This example will be included with our other code examples at a future date; however, at the moment it is still a draft. You may find this example helpful in determining your issue.

    Can you go ahead and post the output from the logic analyzer?

    Additionally, another technique you can try is GPIO debugging. When you enter the ISR in question, set a GPIO pin high, and when you leave, set it low. Use a logic analyzer to monitor this pin along with SCL and SDA. You can follow a similar approach for when you enter and leave functions. This will help to get a better idea of what is happening (or not happening) during code execution.

    Regards,

    Matthew

    /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2017, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *******************************************************************************
     * 
     *                       MSP430 CODE EXAMPLE DISCLAIMER
     *
     * MSP430 code examples are self-contained low-level programs that typically
     * demonstrate a single peripheral function or device feature in a highly
     * concise manner. For this the code may rely on the device's power-on default
     * register values and settings such as the clock configuration and care must
     * be taken when combining code from several examples to avoid potential side
     * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
     * for an API functional library-approach to peripheral configuration.
     *
     * --/COPYRIGHT--*/
    
    //******************************************************************************
    //   MSP430G2xx Demo - USCI_B0, I2C Master multiple byte TX/RX
    //
    //   Description: I2C master communicates to I2C slave sending and receiving
    //   3 different messages of different length. I2C master will enter LPM0 mode
    //   while waiting for the messages to be sent/receiving using I2C interrupt.
    //   ACLK = NA, MCLK = SMCLK = DCO 16MHz.
    //
    //
    //                   MSP430G2553         3.3V
    //                 -----------------   /|\ /|\
    //            /|\ |                 |   |  4.7k
    //             |  |                 |  4.7k |
    //             ---|RST              |   |   |
    //                |                 |   |   |
    //                |             P1.6|---|---+- I2C Clock (UCB0SCL)
    //                |                 |   |
    //                |             P1.7|---+----- I2C Data (UCB0SDA)
    //                |                 |
    //                |                 |
    //
    //   Nima Eskandari
    //   Texas Instruments Inc.
    //   April 2017
    //   Built with CCS V7.0
    //******************************************************************************
    
    #include <msp430.h>
    #include <stdint.h>
    #include <stdbool.h>
    
    //******************************************************************************
    // Example Commands ************************************************************
    //******************************************************************************
    
    #define SLAVE_ADDR  0x48
    
    /* CMD_TYPE_X_SLAVE are example commands the master sends to the slave.
     * The slave will send example SlaveTypeX buffers in response.
     *
     * CMD_TYPE_X_MASTER are example commands the master sends to the slave.
     * The slave will initialize itself to receive MasterTypeX example buffers.
     * */
    
    #define CMD_TYPE_0_SLAVE      0
    #define CMD_TYPE_1_SLAVE      1
    #define CMD_TYPE_2_SLAVE      2
    
    #define CMD_TYPE_0_MASTER      3
    #define CMD_TYPE_1_MASTER      4
    #define CMD_TYPE_2_MASTER      5
    
    #define TYPE_0_LENGTH   1
    #define TYPE_1_LENGTH   2
    #define TYPE_2_LENGTH   6
    
    #define MAX_BUFFER_SIZE     20
    
    /* MasterTypeX are example buffers initialized in the master, they will be
     * sent by the master to the slave.
     * SlaveTypeX are example buffers initialized in the slave, they will be
     * sent by the slave to the master.
     * */
    
    uint8_t MasterType2 [TYPE_2_LENGTH] = {'F', '4', '1', '9', '2', 'B'};
    uint8_t MasterType1 [TYPE_1_LENGTH] = { 8, 9};
    uint8_t MasterType0 [TYPE_0_LENGTH] = { 11};
    
    
    uint8_t SlaveType2 [TYPE_2_LENGTH] = {0};
    uint8_t SlaveType1 [TYPE_1_LENGTH] = {0};
    uint8_t SlaveType0 [TYPE_0_LENGTH] = {0};
    
    //******************************************************************************
    // General I2C State Machine ***************************************************
    //******************************************************************************
    
    
    typedef enum I2C_ModeEnum{
        IDLE_MODE,
        NACK_MODE,
        TX_REG_ADDRESS_MODE,
        RX_REG_ADDRESS_MODE,
        TX_DATA_MODE,
        RX_DATA_MODE,
        SWITCH_TO_RX_MODE,
        SWITHC_TO_TX_MODE,
        TIMEOUT_MODE
    } I2C_Mode;
    
    
    /* Used to track the state of the software state machine*/
    I2C_Mode MasterMode = IDLE_MODE;
    
    /* The Register Address/Command to use*/
    uint8_t TransmitRegAddr = 0;
    
    /* ReceiveBuffer: Buffer used to receive data in the ISR
     * RXByteCtr: Number of bytes left to receive
     * ReceiveIndex: The index of the next byte to be received in ReceiveBuffer
     * TransmitBuffer: Buffer used to transmit data in the ISR
     * TXByteCtr: Number of bytes left to transfer
     * TransmitIndex: The index of the next byte to be transmitted in TransmitBuffer
     * */
    uint8_t ReceiveBuffer[MAX_BUFFER_SIZE] = {0};
    uint8_t RXByteCtr = 0;
    uint8_t ReceiveIndex = 0;
    uint8_t TransmitBuffer[MAX_BUFFER_SIZE] = {0};
    uint8_t TXByteCtr = 0;
    uint8_t TransmitIndex = 0;
    
    
    
    /* I2C Write and Read Functions */
    
    /* For slave device with dev_addr, writes the data specified in *reg_data
     *
     * dev_addr: The slave device address.
     *           Example: SLAVE_ADDR
     * reg_addr: The register or command to send to the slave.
     *           Example: CMD_TYPE_0_MASTER
     * *reg_data: The buffer to write
     *           Example: MasterType0
     * count: The length of *reg_data
     *           Example: TYPE_0_LENGTH
     *  */
    I2C_Mode I2C_Master_WriteReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t count);
    
    /* For slave device with dev_addr, read the data specified in slaves reg_addr.
     * The received data is available in ReceiveBuffer
     *
     * dev_addr: The slave device address.
     *           Example: SLAVE_ADDR
     * reg_addr: The register or command to send to the slave.
     *           Example: CMD_TYPE_0_SLAVE
     * count: The length of data to read
     *           Example: TYPE_0_LENGTH
     *  */
    I2C_Mode I2C_Master_ReadReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t count);
    void CopyArray(uint8_t *source, uint8_t *dest, uint8_t count);
    
    
    I2C_Mode I2C_Master_ReadReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t count)
    {
        /* Initialize state machine */
        MasterMode = TX_REG_ADDRESS_MODE;
        TransmitRegAddr = reg_addr;
        RXByteCtr = count;
        TXByteCtr = 0;
        ReceiveIndex = 0;
        TransmitIndex = 0;
    
        /* Initialize slave address and interrupts */
        UCB0I2CSA = dev_addr;
        IFG2 &= ~(UCB0TXIFG + UCB0RXIFG);       // Clear any pending interrupts
        IE2 &= ~UCB0RXIE;                       // Disable RX interrupt
        IE2 |= UCB0TXIE;                        // Enable TX interrupt
    
        UCB0CTL1 |= UCTR + UCTXSTT;             // I2C TX, start condition
        __bis_SR_register(CPUOFF + GIE);              // Enter LPM0 w/ interrupts
    
        return MasterMode;
    
    }
    
    
    I2C_Mode I2C_Master_WriteReg(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t count)
    {
        /* Initialize state machine */
        MasterMode = TX_REG_ADDRESS_MODE;
        TransmitRegAddr = reg_addr;
    
        //Copy register data to TransmitBuffer
        CopyArray(reg_data, TransmitBuffer, count);
    
        TXByteCtr = count;
        RXByteCtr = 0;
        ReceiveIndex = 0;
        TransmitIndex = 0;
    
        /* Initialize slave address and interrupts */
        UCB0I2CSA = dev_addr;
        IFG2 &= ~(UCB0TXIFG + UCB0RXIFG);       // Clear any pending interrupts
        IE2 &= ~UCB0RXIE;                       // Disable RX interrupt
        IE2 |= UCB0TXIE;                        // Enable TX interrupt
    
        UCB0CTL1 |= UCTR + UCTXSTT;             // I2C TX, start condition
        __bis_SR_register(CPUOFF + GIE);              // Enter LPM0 w/ interrupts
    
        return MasterMode;
    }
    
    
    void CopyArray(uint8_t *source, uint8_t *dest, uint8_t count)
    {
        uint8_t copyIndex = 0;
        for (copyIndex = 0; copyIndex < count; copyIndex++)
        {
            dest[copyIndex] = source[copyIndex];
        }
    }
    
    
    
    //******************************************************************************
    // Device Initialization *******************************************************
    //******************************************************************************
    
    
    void initClockTo16MHz()
    {
        if (CALBC1_16MHZ==0xFF)                  // If calibration constant erased
        {
            while(1);                               // do not load, trap CPU!!
        }
        DCOCTL = 0;                               // Select lowest DCOx and MODx settings
        BCSCTL1 = CALBC1_16MHZ;                    // Set DCO
        DCOCTL = CALDCO_16MHZ;
    }
    
    void initGPIO()
    {
        P1DIR |= BIT0 + BIT1 + BIT2 + BIT3 + BIT4;
        P1OUT &= ~(BIT0 + BIT1 + BIT2 + BIT3 + BIT4);
    
        P1SEL |= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0
        P1SEL2|= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0
    }
    
    void initI2C()
    {
        UCB0CTL1 |= UCSWRST;                      // Enable SW reset
        UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;     // I2C Master, synchronous mode
        UCB0CTL1 = UCSSEL_2 + UCSWRST;            // Use SMCLK, keep SW reset
        UCB0BR0 = 160;                            // fSCL = SMCLK/160 = ~100kHz
        UCB0BR1 = 0;
        UCB0I2CSA = SLAVE_ADDR;                   // Slave Address
        UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation
        UCB0I2CIE |= UCNACKIE;
    }
    
    
    //******************************************************************************
    // Main ************************************************************************
    // Send and receive three messages containing the example commands *************
    //******************************************************************************
    
    int main(void) {
    
        WDTCTL = WDTPW | WDTHOLD;	              // Stop watchdog timer
    
        initClockTo16MHz();
        initGPIO();
        initI2C();
    
    
        I2C_Master_WriteReg(SLAVE_ADDR, CMD_TYPE_0_MASTER, MasterType0, TYPE_0_LENGTH);
        I2C_Master_WriteReg(SLAVE_ADDR, CMD_TYPE_1_MASTER, MasterType1, TYPE_1_LENGTH);
        I2C_Master_WriteReg(SLAVE_ADDR, CMD_TYPE_2_MASTER, MasterType2, TYPE_2_LENGTH);
    
        I2C_Master_ReadReg(SLAVE_ADDR, CMD_TYPE_0_SLAVE, TYPE_0_LENGTH);
        CopyArray(ReceiveBuffer, SlaveType0, TYPE_0_LENGTH);
    
        I2C_Master_ReadReg(SLAVE_ADDR, CMD_TYPE_1_SLAVE, TYPE_1_LENGTH);
        CopyArray(ReceiveBuffer, SlaveType1, TYPE_1_LENGTH);
    
        I2C_Master_ReadReg(SLAVE_ADDR, CMD_TYPE_2_SLAVE, TYPE_2_LENGTH);
        CopyArray(ReceiveBuffer, SlaveType2, TYPE_2_LENGTH);
    
        __bis_SR_register(LPM0_bits + GIE);
    	return 0;
    }
    
    
    //******************************************************************************
    // I2C Interrupt For Received and Transmitted Data******************************
    //******************************************************************************
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = USCIAB0TX_VECTOR
    __interrupt void USCIAB0TX_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCIAB0TX_VECTOR))) USCIAB0TX_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
      if (IFG2 & UCB0RXIFG)                 // Receive Data Interrupt
      {
          //Must read from UCB0RXBUF
          uint8_t rx_val = UCB0RXBUF;
    
          if (RXByteCtr)
          {
              ReceiveBuffer[ReceiveIndex++] = rx_val;
              RXByteCtr--;
          }
    
          if (RXByteCtr == 1)
          {
              UCB0CTL1 |= UCTXSTP;
          }
          else if (RXByteCtr == 0)
          {
              IE2 &= ~UCB0RXIE;
              MasterMode = IDLE_MODE;
              __bic_SR_register_on_exit(CPUOFF);      // Exit LPM0
          }
      }
      else if (IFG2 & UCB0TXIFG)            // Transmit Data Interrupt
      {
          switch (MasterMode)
          {
              case TX_REG_ADDRESS_MODE:
                  UCB0TXBUF = TransmitRegAddr;
                  if (RXByteCtr)
                      MasterMode = SWITCH_TO_RX_MODE;   // Need to start receiving now
                  else
                      MasterMode = TX_DATA_MODE;        // Continue to transmision with the data in Transmit Buffer
                  break;
    
              case SWITCH_TO_RX_MODE:
                  IE2 |= UCB0RXIE;              // Enable RX interrupt
                  IE2 &= ~UCB0TXIE;             // Disable TX interrupt
                  UCB0CTL1 &= ~UCTR;            // Switch to receiver
                  MasterMode = RX_DATA_MODE;    // State state is to receive data
                  UCB0CTL1 |= UCTXSTT;          // Send repeated start
                  if (RXByteCtr == 1)
                  {
                      //Must send stop since this is the N-1 byte
                      while((UCB0CTL1 & UCTXSTT));
                      UCB0CTL1 |= UCTXSTP;      // Send stop condition
                  }
                  break;
    
              case TX_DATA_MODE:
                  if (TXByteCtr)
                  {
                      UCB0TXBUF = TransmitBuffer[TransmitIndex++];
                      TXByteCtr--;
                  }
                  else
                  {
                      //Done with transmission
                      UCB0CTL1 |= UCTXSTP;     // Send stop condition
                      MasterMode = IDLE_MODE;
                      IE2 &= ~UCB0TXIE;                       // disable TX interrupt
                      __bic_SR_register_on_exit(CPUOFF);      // Exit LPM0
                  }
                  break;
    
              default:
                  __no_operation();
                  break;
          }
      }
    }
    
    
    //******************************************************************************
    // I2C Interrupt For Start, Restart, Nack, Stop ********************************
    //******************************************************************************
    
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = USCIAB0RX_VECTOR
    __interrupt void USCIAB0RX_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCIAB0RX_VECTOR))) USCIAB0RX_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
        if (UCB0STAT & UCNACKIFG)
        {
            UCB0STAT &= ~UCNACKIFG;             // Clear NACK Flags
        }
        if (UCB0STAT & UCSTPIFG)                        //Stop or NACK Interrupt
        {
            UCB0STAT &=
                ~(UCSTTIFG + UCSTPIFG + UCNACKIFG);     //Clear START/STOP/NACK Flags
        }
        if (UCB0STAT & UCSTTIFG)
        {
            UCB0STAT &= ~(UCSTTIFG);                    //Clear START Flags
        }
    }
    

  • Hello Shankar,

    Do you have any updates on this issue?

    Regards,
    Matthew
  • I dropped MSp for this project and I went ahead with other controller that made my life simpler

**Attention** This is a public forum