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;
}