I want to read the data from TMP006EVM into msp430g2553 using USCI I2C. So i connected SCL of MSP430g2553 to SCL of TMP006 and similarly for SDA and Vcc and Gnd .
I have also connected P1.1 of msp430g2553 to DRDY pin of TMP006. I used the following program .While USing it runs well till " UCB0CTL1 |= UCTR + UCTXSTT;"
after this line, the "IFG2&UCB0TXIFG" flag is set which means that the slave address is successfully transmitted and the "UCB0STAT&UCNACKIFG" flag is not raised which means the slave has acknowledged the address. After this in order to configure the registers of TMP006 I had to write data from MSP .so i used "UCB0TXBUF = 0x02;"
The data here is not getting transferred to the TMP006 register, and I have come to know this because if the data is transferred UCB0TXBUF becomes empty and "UCB0STAT&UCNACKIFG" is raised .But for me , the "UCB0STAT&UCNACKIFG" becomes zero instead and I have tried this with and without using "IFG2 &= ~UCB0TXIFG;"
and the result is the same and my program gets stuck in this loop "while (!(IFG2&UCB0TXIFG));" I have pasted my code at the bottom and help me resolve this problem and also correct me if I am wrong . Pls it is urgent that I want this done and also thanks in advance.
/*
* main.c
*/
#include<msp430g2553.h>
#include<stdio.h>
#define D1 BIT1
#define LED1 BIT0
void main(void) {
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= LED1;
P1OUT &= ~LED1;
P1SEL |= BIT6+BIT7; // Assign I2C pins to USCI_B0
P1REN |= BIT1;
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
UCB0BR1 = 0;
UCB0I2CSA = 0x40; // Slave Address is 048h
UCB0CTL1 &= ~UCSWRST;
int i;
UCB0CTL1 |= UCTR + UCTXSTT;
for ( i=0;i<100;i++)
{
}
while( UCB0STAT & UCBBUSY );
while((UCB0STAT&UCNACKIFG)!= 0)
{
}
IFG2 &= ~UCB0TXIFG;
UCB0TXBUF = 0x02;
while( UCB0STAT & UCBBUSY );
while (!(IFG2&UCB0TXIFG)) ////This is the part where my program hangs .
{
}
UCB0TXBUF = 0x75;
while (!(IFG2&UCB0TXIFG))
{
}
UCB0TXBUF = 0x00;
while (!(IFG2&UCB0TXIFG))
{
}
UCB0CTL1 |= UCTXSTP;
while ((UCB0CTL1&UCTXSTP))
{
}
while((P1IN & D1) == 0)
{
}
for ( i=0;i<30;i++)
{
}
P1OUT |= LED1;
}