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.

i2c problem in msp430fr5729

Other Parts Discussed in Thread: MSP430FR5729, MSP430F2013

i am using msp430fr5729 and try to interface one i2c based sensor but can suceed. here i attach data sheet of sensor and my code

/////////////////////////////////////////////////////////////////////////////////////////////////////

#include <msp430.h>
unsigned char RXData;
volatile unsigned char *prxdata,rxdata[50]={0,0,0,0},value,flag;
volatile unsigned char bytecount=0;
void read_sensor(void);
void clock_configure();
void init();
void init_i2c();
void sendmes_request();
void read_data();
void init()
{
P1SEL0=0x30;
P1SEL1=0xC0;
P1DIR =0x30;

P2SEL0=0x00;
P2SEL1=0x00;
P2DIR =0x98;

P3SEL0=0x00;
P3SEL1=0x00;
P3DIR =0x80;

PJSEL0=0x00;
PJSEL1=0x00;

}
void clock_configure()
{

CSCTL0_H = 0xA5;
CSCTL1 |= DCOFSEL0 + DCOFSEL1; // Set max. DCO setting = 8MHz
CSCTL2 = SELA_3 + SELS_3 + SELM_3; // set ACLK = MCLK = DCO
CSCTL3 = DIVA_3 + DIVS_3 + DIVM_3; // set all dividers to 1MHz
CSCTL4 &= ~0x00C0;

__delay_cycles(1000);
__delay_cycles(1000);
__delay_cycles(1000);
__delay_cycles(1000);
do
{
CSCTL5 &= ~XT1OFFG;
// Clear XT1 fault flag
SFRIFG1 &= ~OFIFG;
}while (SFRIFG1&OFIFG);
}

void init_i2c()
{
UCB0CTLW0 |= UCSWRST;
UCB0CTLW0 |= UCMODE_3 + UCMST +UCSSEL_3+UCSYNC;
UCB0BRW = 0x0008;
UCB0I2CSA = 0x0027;
UCB0CTLW0 &=~UCSWRST;
}
int main (void)

{

WDTCTL = WDTPW + WDTHOLD;
// Init SMCLK = MCLk = ACLK = 1MHz
__bis_SR_register(GIE); // Enter LPM0 w/ interrupt

clock_configure();
init();
init_i2c();
// Configure pins
while (1)
{
read_sensor();
__delay_cycles(1000);
__delay_cycles(1000);
__delay_cycles(1000);
P2OUT &=~(BIT3+BIT4);
//__delay_cycles(1000);

}


}

void read_sensor(void)
{

sendmes_request();
__delay_cycles(1000);
read_data();

}

void sendmes_request()
{
P2OUT |=BIT3;
UCB0I2CSA = 0x0027;
UCB0CTLW0 |= UCTR;
UCB0IE |= UCNACKIE;
while (UCB0CTL1 & UCTXSTP);
UCB0CTL1 |= UCTXSTP+UCTXSTT;

}
void read_data()
{
P2OUT |=BIT4;
UCB0I2CSA = 0x0027;
UCB0CTLW0 &=~UCTR;
prxdata=&rxdata[0];
bytecount=4;
flag=0;
UCB0IE |= UCNACKIE+UCRXIE;
while (UCB0CTL1 & UCTXSTP);
UCB0CTL1 |= UCTXSTT;
while(flag!=2);

}

#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,0x1E))

{
case 0x00: break; // Vector 0: No interrupts break;
case 0x02: break; // Vector 2: ALIFG break;
case 0x04:
UCB0CTL1 |= UCTXSTP; // I2C start condition
bytecount=0;
UCB0IFG &=~UCNACKIFG;
flag=2;
P3OUT ^=BIT7;
break; // Vector 4: NACKIFG break;
case 0x06: break; // Vector 6: STTIFG break;
case 0x08: break; // Vector 8: STPIFG break;
case 0x0a: break; // Vector 10: RXIFG3 break;
case 0x0c: break; // Vector 14: TXIFG3 break;
case 0x0e: break; // Vector 16: RXIFG2 break;
case 0x10: break; // Vector 18: TXIFG2 break;
case 0x12: break; // Vector 20: RXIFG1 break;
case 0x14: break; // Vector 22: TXIFG1 break;
case 0x16:

//value= UCB0RXBUF;
P2OUT ^=BIT7;
*prxdata= (unsigned char)UCB0RXBUF;
prxdata++;
if(bytecount>0)
bytecount--;
if(bytecount==1)
UCB0CTL1 |= UCTXSTP;
if(bytecount==0)
flag=2;
UCB0IFG &=~UCRXIFG0;

break; // Vector 24: RXIFG0 break;
case 0x18:
//while( UCB0CTL1 & UCTXSTT);
// UCB0CTL1 |= UCTXSTP;
// UCB0TXBUF = 0x4e;
// UCB0CTLW0 &= !UCTR; //receive mode
// UCB0TBCNT |= 0x0004;
// UCB0CTLW0 |= UCTXSTT; // generate start condition.
UCB0TXBUF=0x4E;
UCB0CTL1 |= UCTXSTP;
//flag=1;
UCB0IFG &=~UCTXIFG0;
break; // Vector 26: TXIFG0 break;
case 0x1a:
// P3DIR |= BIT7;
// P3OUT |= BIT7;
break; // Vector 28: BCNTIFG break;
case 0x1c: break; // Vector 30: clock low timeout break;
case 0x1e: break; // Vector 32: 9th bit break;
default: break;

}

}

//////////////////////////////////////////////////////////////////////////////////////

and i have one question is i set slave address register=0x27. during start condition what controller really send 0x27 or 0x4e???? pull ups are thare of 4.7k.some time even start condition flag is not cleard  after sendmes() function.i already read this sensor through msp430f2013.but in this controller its worst.

I2C Comms HumidIcon TN_009061-2-EN_Final_07Jun12.pdfDatasheet - HumidIcon HIH9000 009076-3-EN.pdf

  • Hi Karan,
    I'm looking into this for you.

    Is this the same code that you are using for both 'F2013 and 'FR5729?

    Is the sensor responding at all?


    Best regards,
    Cameron
  • Karan,
    I think your problem is that in sendmes(), your are issuing a START and STOP condition a the same time.

    Setting UCTXSTP generates a STOP condition after the next acknowledge from the slave. If UCTXSTP is set during the transmission of the slave address or while the eUSCI_B module waits for data to be written into UCBxTXBUF, a STOP condition is generated, even if no data was transmitted to the slave. In this case, the UCSTPIFG is set. When transmitting a single byte of data, the UCTXSTP bit must be set while the byte is being transmitted or any time after transmission begins, without writing new data into UCBxTXBUF. Otherwise, only the address is transmitted. When the data is transferred from the buffer to the shift register, UCTXIFG0 is set, indicating data transmission has begun, and the UCTXSTP bit may be set. When UCASTPx = 10 is set, the byte counter is used for STOP generation and the user does not need to set the UCTXSTP. This is recommended when transmitting only one byte.

    The MSP Transmits the slave address, then waits for an ACK, and then transmits the data.

    You should also enable the transmit interrupt with UCTXIE0, since your ISR uses vector 26.

    There is some really good demonstration code at the following link. Check out MSP430FR57xx_uscib0_i2c_04 and 06. www.ti.com/.../slac491



    If this fixes the issue PLEASE, click "Verify Answer".

    Best regards,
    Cameron
  • May I close this issue out, or do you still have questions?

**Attention** This is a public forum