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.

Interfacing AT24C02 EEPROM IC with MSP430G2553 launchpad

Other Parts Discussed in Thread: MSP430G2553

  Hi,

   I am currently working with MSP430G2553 I2C and trying to interface it with AT24C02 EEPROM IC. I have tried with the following code. I have given that the slave address for eeprom as 0x50 and memory location for writing data as 0x05. The code does not exit from the highlighted while condition in blue.  SCL, SDA lines  are pulled high. A0,A1,A2,WP pins of EEPROM are connected to ground. Kindly help us to find out why the code isnt executing beyond the highlighted while condition. 

#include<msp430g2553.h>


int rLoop; //loop counter
void I2C_Write_EEProm();
void I2C_Read_EEProm();
void main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop watchdog
if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
{
while(1); // If calibration constants erased
// do not load, trap CPU!!
}
BCSCTL1 = CALBC1_1MHZ; 
DCOCTL = CALDCO_1MHZ;
P1DIR |= 0x01; 
P2DIR |= 0x01;
P2OUT = 0X00;

P1SEL |= BIT6 + BIT7; 
P1SEL2|= BIT6 + BIT7;
UCB0CTL1 |= UCSWRST; 
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; 
UCB0CTL1 = UCSSEL_2 + UCSWRST; 
UCB0BR0 = 12; 
UCB0BR1 = 0;
UCB0I2CSA = 0x50; 
UCB0CTL1 &= ~UCSWRST; 
IE2 |= UCB0TXIE; 
__bis_SR_register(GIE); 


while(1)
{
I2C_Write_EEProm();


I2C_Read_EEProm();
if(rLoop=='a')
{
P2OUT = 0X01;
}
}
}

void I2C_Write_EEProm()
{
__disable_interrupt(); 
while (UCB0STAT & UCBBUSY); 
UCB0I2CSA = 0x50; 
while (UCB0CTL1 & UCTXSTP); 
UCB0CTL1 |= UCTR + UCTXSTT; 
while (UCB0CTL1 & UCTXSTT); 

UCB0TXBUF = 0x05;
while ((IFG2 & UCB0TXIFG) != UCB0TXIFG); 
UCB0TXBUF = 'a'; 
while ((IFG2 & UCB0TXIFG) != UCB0TXIFG); 
UCB0CTL1 |= UCTXSTP;
while ((UCB0STAT & UCSTPIFG) == UCSTPIFG);
__delay_cycles(6000); 
__enable_interrupt();

}

void I2C_Read_EEProm()
{
while (UCB0STAT & UCBBUSY); 
UCB0I2CSA = 0x50;

UCB0CTL1 |= UCTR + UCTXSTT; 
UCB0TXBUF = 0x05; 

while (UCB0CTL1 & UCTXSTT); 
while ((IFG2 & UCB0TXIFG) != UCB0TXIFG); 


UCB0CTL1 &= ~UCTR; 
UCB0CTL1 |= UCTXSTT; 
while (UCB0CTL1 & UCTXSTT); 

while ((IFG2 & UCB0RXIFG) != UCB0RXIFG); 
rLoop= UCB0RXBUF; 
UCB0CTL1 |= UCTXSTP; 

}

  • Hi Rohini,

    Rohini Menon said:
    SCL, SDA lines  are pulled high

    With two external resistors?

    Do you have a scope to see if there is some action at SCL and SDA? Maybe SCL is held low? Did you search the forum for similar problems already? I know that there are more than you having problems with polling-controlled I²C communication.

    Dennis

**Attention** This is a public forum