Other Parts Discussed in Thread: MSP430FR2522
Tool/software: Code Composer Studio
Hi,
We are developing a product in which TM4C129ENCPDT (I2C master) communicates with multiple MSP430FR2522IPW16 (I2C slaves) .
I've taken the i2c example codes given for i2c for MSP430 and modified them to working as polling method.
For checking purpose and understanding the I2C master slave concept, I've connected TM4C and one MSP430 ICs and from TM4C I request continuous data and from MSP430 I repond to the request starting from 1, 2 , 3 .... 255.
TM4C code (I2C Master):
while(1)
{
UARTprintf("Data from Slave 1 (0x0A):\n");
UARTFlushTx(false);
I2CMasterSlaveAddrSet(I2C1_BASE, 0x0A, true);
SysCtlDelay(40000*10);
for(i=0;i<5;i++)
{
I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
//wait for MCU to finish transaction
//while(I2CMasterBusy(I2C1_BASE));
SysCtlDelay(40000);
//while (!(I2CMasterBusy(I2C1_BASE))); //Wait till end of transaction
while (I2CMasterBusy(I2C1_BASE)); //Wait till end of transaction
SysCtlDelay(40000);
//return data pulled from the specified register
rx_data = I2CMasterDataGet(I2C1_BASE);
UARTprintf("rx_data=%d\n",rx_data);
UARTFlushTx(false);
}
}
MSP430 code (I2C slave):
// Configure USCI_B0 for I2C mode
UCB0CTLW0 = UCSWRST; // Software reset enabled
UCB0CTLW0 |= UCMODE_3 | UCSYNC; // I2C mode, sync mode
UCB0I2COA0 = 0x0A | UCOAEN; // own address is 0x48 + enable
UCB0CTLW0 &= ~UCSWRST; // clear reset register
unsigned char i=0;
volatile unsigned char TXData = 1;
while(1)
{
if(UCB0IFG & UCTXIFG0)
{
UCB0IFG &= ~UCTXIFG0; // Clear Tx condition int flag
UCB0TXBUF = TXData++;
P2OUT |= BIT2; __delay_cycles(100000); P2OUT ^= BIT2; __delay_cycles(100000); // some led indication that data request has come
}
P1OUT ^= BIT0; __delay_cycles(100000);// some led indication that code is still running in the infinite while
}
}
While reading from TM4C side, I'm missing some data as shown in the picture.
Thank You for your time!
