Hi,
This is my first project on MSP432 . I have eeprom(24AA128) and temperature sensor connected to master MSP432 via I2C. I could write data to eeprom at any locations but I am facing data repetition while reading from the same location. Please see the read and write portion of the code below.
void eeprom_write() {
/* Select Port 1 for I2C - Set Pin 6, 7 to input Primary Module Function
*/
char eeprom_data[10] = "ABCD_EFGH";
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P1,
GPIO_PIN6 + GPIO_PIN7,
GPIO_PRIMARY_MODULE_FUNCTION);
/* Initializing I2C Master to SMCLK at 100khz with no autostop */
MAP_I2C_initMaster(EUSCI_B0, &i2cConfig);
/* Specify slave address */
MAP_I2C_setSlaveAddress(EUSCI_B0, 0x51);
/* Enable I2C Module to start operations */
MAP_I2C_enableModule(EUSCI_B0);
/* Making sure the last transaction has been completely sent out */
while (MAP_I2C_masterIsStopSent(EUSCI_B0));
MAP_I2C_masterSendMultiByteStart(EUSCI_B0, 0x00); // Start + 1Byte Reg Address High
MAP_I2C_masterSendMultiByteNext(EUSCI_B0, 0x00); // Start + 1Byte Reg Address Low
for (j = 0; j <= 32; j++)
{
sprintf(str, "0x%02x",eeprom_data[j] );
data = (int) strtol(str, NULL, 0);
if (j == 32)
MAP_I2C_masterSendMultiByteFinish(EUSCI_B0, data);
else
MAP_I2C_masterSendMultiByteNext(EUSCI_B0, data);
}
}
void eeprom_read() {
/* Select Port 1 for I2C - Set Pin 6, 7 to input Primary Module
* Function,(UCB0SIMO/UCB0SDA, UCB0SOMI/UCB0SCL).
*/
MAP_GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P1,
GPIO_PIN6 + GPIO_PIN7,
GPIO_PRIMARY_MODULE_FUNCTION);
/* Initializing I2C Master to SMCLK at 100khz with no autostop*/
MAP_I2C_initMaster(EUSCI_B0, &i2cConfig);
/* Specify EEPROM address */
MAP_I2C_setSlaveAddress(EUSCI_B0, 0x51);
/* Enable I2C Module to start operations */
MAP_I2C_enableModule(EUSCI_B0);
rx_data = 0;
for(j = 0; j < length; j++) {
/* Making sure the last transaction has been completely sent out */
while (MAP_I2C_masterIsStopSent(EUSCI_B0));
/* Send out EEPROM word address (2 databytes) */
MAP_I2C_masterSendMultiByteStart(EUSCI_B0, 0x00);
MAP_I2C_masterSendMultiByteNext(EUSCI_B0, tx_data[j]);
/*---------------------------------------------*/
/* Now we need to initiate the read*/
/* Wait until Byte has been output to shift register*/
while (!(EUSCI_B0->IFG & EUSCI_B_IFG_TXIFG0));
/*Send the restart condition,read one byte,send the stop condition right away*/
EUSCI_B0->CTLW0 &= ~(EUSCI_B_CTLW0_TR);
EUSCI_B0->CTLW0 |= EUSCI_B_CTLW0_TXSTT;
while (MAP_I2C_masterIsStartSent(EUSCI_B0));
EUSCI_B0->CTLW0 |= EUSCI_B_CTLW0_TXSTP;
while (!(EUSCI_B0->IFG & EUSCI_B_IFG_RXIFG0));
rx_data = EUSCI_B0->RXBUF;
while (!(UCA0IFG & UCTXIFG));
UCA0TXBUF = rx_data;
}
}
Please find the Output that I got on my UART terminal with register on first and its data on second,
0x00 A 0x01 B 0x02 B 0x03 C 0x04 D 0x05 _ 0x06 E 0x07 F 0x08
0x00, 0x01... are the registers I used to write the data. You could see a repetition of the actual data on register 0x01 and 0x02.
when I provided with, eeprom_data1[] = "ABCD_EFGH" and eeprom_data2[] = "IJKL_MNOP", I could find the same repetition of data in registers 2 and 3.
