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.

MSP430F5438A interface to a Microchip 24LC128 I2C Serial EEPROM

Hello,

I have looked at this post 

http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/31708.aspx

and am trying to get duplicate code working on my board.

The code fails on the EEPROMWrite function; the code sets the STOP bit to send the STOP condition to the eeprom; but the stop condition never gets sent and the status register shows Bus Busy. The STOP bit never gets reset to 0. Can someone provide suggestions as to why? Will greatly appreciate it.

The code snippet is below. Note that the InitEEPROM function is called before calling the Write function.

Thanks in advance.

int EEPROMWrite(char *pcBuf, int iNumBytesToWrite, unsigned int uiPageToWrite) {

int i;
unsigned int uiStartAddr;
char *pBuf;

pBuf = pcBuf;

if (iNumBytesToWrite > 64) return (-1);

uiStartAddr = 0x0000;

UCB3CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition

while((UCB3IFG&0x0002)==0x00); //check for transmit interrupt flag

__delay_cycles(100);

UCB3TXBUF = (uiStartAddr)>>8;

__delay_cycles(100);

while((UCB3IFG&0x0002)==0x00); //check for transmit interrupt flag

UCB3TXBUF = (unsigned char) uiStartAddr;

__delay_cycles(100);

while((UCB3IFG&0x0002)==0x00); //check for transmit interrupt flag

for(i=0;i<iNumBytesToWrite;i++) {
UCB3TXBUF = *pBuf;
pBuf++;
while((UCB3IFG&0x0002)==0x00); //check for transmit interrupt flag
}

UCB3CTL1 |= UCTXSTP;

while(UCB3CTL1&UCTXSTP); //Send the stop condition

ShortDelay(1000); //allow time for eeprom to complete internal write operation

return 0;
}


int InitEEPROM() {
//init the i2c port for the eeprom
P10SEL |= 0x06; // Assign I2C pins to USCI_B3
UCB3CTL1 |= UCSWRST; // Enable SW reset
UCB3CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
UCB3CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
UCB3BR0 = 12; // fSCL = SMCLK/12 = ~100kHz; with val =3 , fSCL = SMCLK/3 = ~400kHz
UCB3BR1 = 0;
UCB3I2CSA = 0x50; // Slave Address is 050h
UCB3CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
uci3cNumBytesToXmit = 0; // Load TX byte counter
uci3cNumBytesToRecv = 0;
uci3cRXByteCtr = 0;
UCB3CTL1 &= ~UCTR; //set up as receiver

return (0);
}

Thanks in advance.

**Attention** This is a public forum