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.

MSP430FR2311: TMP275 Sensor Interface with MSP430FR2311 uC

Part Number: MSP430FR2311
Other Parts Discussed in Thread: TMP275,

I have a interface TMP275 Temperature Sensor with MSP430FR2311 with the help of I2C Protocol.

The below code is stuck in the TX ISR of first function. 

Please check my code is correct  or whether it needs any modification for proper working.

#include <msp430fr2311.h>

//unsigned int Slave_Address[3] = {0x0048, 0x0048, 0x004A};
//int Slave_Flag;
unsigned int TxData[3];
unsigned int RX_Data[2];
int Tx_Counter;
int RX_Counter;
unsigned int Tx_Int_Counter;
unsigned int Rx_Int_Counter;
//volatile int Reg_Add1;
void TX_Data_For_Data_Demand(unsigned int Reg_Add);
void TX_Data_Format_Bit(unsigned int Reg_Add,unsigned int Reg_Data);

int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer

// Configure Pins for I2C
P1SEL0 |= BIT2 | BIT3; // I2C pins

// Disable the GPIO power-on default high-impedance mode
// to activate previously configured port settings
PM5CTL0 &= ~LOCKLPM5;

// Configure USCI_B0 for I2C mode
UCB0CTLW0 |= UCSWRST; // put eUSCI_B in reset state
UCB0CTLW0 |= UCMODE_3 | UCMST | UCSYNC; // I2C master mode, SMCLK
UCB0BRW = 0x8; // baudrate = SMCLK / 8
UCB0I2CSA = 0x0048;
UCB0CTLW0 &= ~UCSWRST; // clear reset register

__bis_SR_register(GIE);

TX_Data_Format_Bit(0x01,0x20); // Configuration Register
while (UCB0CTLW0 & UCTXSTP); // Ensure stop condition got sent


while(1)
{

while (UCB0CTLW0 & UCTXSTP); // Ensure stop condition got sent

TX_Data_For_Data_Demand(0x00);
while (UCB0CTLW0 & UCTXSTP); // Ensure stop condition got sent

}
}


#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = USCI_B0_VECTOR
__interrupt void USCIB0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCIB0_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(UCB0IV,USCI_I2C_UCBIT9IFG))
{
case USCI_NONE: break; // Vector 0: No interrupts break;
case USCI_I2C_UCALIFG: break;
case USCI_I2C_UCNACKIFG:
UCB0CTL1 |= UCTXSTT; //resend start if NACK
break; // Vector 4: NACKIFG break;
case USCI_I2C_UCSTTIFG: break; // Vector 6: STTIFG break;
case USCI_I2C_UCSTPIFG: break; // Vector 8: STPIFG break;
case USCI_I2C_UCRXIFG3: break; // Vector 10: RXIFG3 break;
case USCI_I2C_UCTXIFG3: break; // Vector 14: TXIFG3 break;
case USCI_I2C_UCRXIFG2: break; // Vector 16: RXIFG2 break;
case USCI_I2C_UCTXIFG2: break; // Vector 18: TXIFG2 break;
case USCI_I2C_UCRXIFG1: break; // Vector 20: RXIFG1 break;
case USCI_I2C_UCTXIFG1: break; // Vector 22: TXIFG1 break;
case USCI_I2C_UCRXIFG0:
RX_Data[RX_Counter] = UCB0RXBUF;
RX_Counter++;
Rx_Int_Counter++;
break; // Vector 24: RXIFG0 break;
case USCI_I2C_UCTXIFG0: // Check TX byte counter
// Reg_Add1 = TxData[Tx_Counter];
// if (Tx_Counter > 0)
//{
UCB0TXBUF = TxData[Tx_Counter];
Tx_Counter--;
Tx_Int_Counter++;
//}
break; // Vector 26: TXIFG0 break;
case USCI_I2C_UCBCNTIFG: break; // Vector 28: BCNTIFG
case USCI_I2C_UCCLTOIFG: break; // Vector 30: clock low timeout
case USCI_I2C_UCBIT9IFG: break; // Vector 32: 9th bit
default: break;
}
}


void TX_Data_Format_Bit(unsigned int Reg_Add, unsigned int Reg_Data)
{
Tx_Counter = 2;

//UCB0IE |= UCNACKIE; // transmit and NACK interrupt enable
TxData[2] = Reg_Add;
TxData[1] = Reg_Data;
while (UCB0CTLW0 & UCTXSTP); // Ensure stop condition got sent
UCB0CTLW0 |= UCTR | UCTXSTT; // I2C TX, start condition
UCB0IE |= UCTXIE0; // Clear USCI_B0 TX int flag
//__bis_SR_register(GIE);

// while(Tx_Counter > 0)
while(Tx_Counter != 0)
{
__no_operation();
}


UCB0CTLW0 |= UCTXSTP;
UCB0IE &= ~UCTXIE0; // Clear USCI_B0 TX int flag

//UCB0IE &= ~UCNACKIE;

}

void TX_Data_For_Data_Demand(unsigned int Reg_Add)
{
Tx_Counter = 1;
TxData[1] = Reg_Add;
RX_Counter = 0;
while (UCB0CTLW0 & UCTXSTP); // Ensure stop condition got sent
UCB0CTLW0 |= UCTR | UCTXSTT; // I2C TX, start condition
UCB0IE |= UCTXIE0; // transmit and NACK interrupt enable

while(Tx_Counter != 0)
{
__no_operation();
}

UCB0IE &= ~UCTXIE0; // Clear USCI_B0 TX int flag
__no_operation();


//UCB0CTLW0 |= UCTXSTP;
//UCB0CTVALUE = UCB0CTLW0;

while(UCB0CTLW0 & UCTXSTP); // Ensure stop condition got sent
UCB0CTLW0 &= ~UCTR;
UCB0CTLW0 |= UCTXSTT; // I2C TX, start condition
UCB0IE |= UCRXIE0; // transmit and NACK interrupt enable

while(RX_Counter < 2)
{
__no_operation();
}

UCB0CTLW0 |= UCTXSTP;
UCB0IE &= ~UCRXIE0; // Clear USCI_B0 TX int flag
__no_operation();

}

**Attention** This is a public forum