Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

Compiler/MSP430F5632: Why is there an unknown error while I2C connection

$
0
0

Part Number:MSP430F5632

Tool/software: TI C/C++ Compiler

Hi everyone,

I have work on a project with communications.

There are two chip on the PCB, and they are MSP430F2122(I2C master) and MSP430F5632(I2C slave)

The operation of the project is,

2122 transmit UART data to chip1 -> 2122 receive UART data from chip1 ->2122 transmit UART data to chip2 -> ...(polling to all chips of the project) -> 2122 read and write I2C data to 5632 ->2122 transmit UART data to chip1 -> 2122 receive UART data from chip1 ->...(repeat)

After the whole system is reset, each operations seems normal.

UART can run in a correct way that is same as my setting and never miss data under communicating.

But when the 2122 run I2C communication for several times, 2122 keeps being reset.(When I2C stuck, I clear WTDCTL to reset 2122)

How can I solve the problem of the I2C communication error?

I guess there are something wrong in 2122 or 5632, but I don't know why.

The protocol is below,

Frequency for I2C operation : about 100KHz

Address of 5633(I2C slave) : 0x48

Number of data to 5633 : 57 bytes

Number of data from 5633 : 4 bytes

And the code is below,

2122:

void I2C_Multiple_Read_Write(unsigned char Length,unsigned short number_of_read)
{
unsigned int i;
unsigned short loop;
_DINT();
while (UCB0STAT & UCBUSY); // wait until I2C module has
// finished all operations
//Transmit
UCB0CTL1 |= UCTR; // UCTR=1 => Transmit Mode
IFG2 &= ~UCB0TXIFG;// disable Receive ready interrupt
IE2 &= ~UCB0RXIE;// enable Transmit ready interrupt
IE2 |= UCB0TXIE;
UCB0CTL1|= UCTXSTT; // send start condition
while(UCB0CTL1 & UCTXSTT) // Ensure start condition got sent
{
if(!(UCNACKIFG & UCB0STAT)) // Break out if ACK received
break;
}
for(loop=0;loop<Length;loop++)
{
while (!(IFG2 & UCB0TXIFG)); // check if UCB0TXBUF=empty
UCB0TXBUF = I2C_data[loop];
i=0;
while (!(IFG2 & UCB0TXIFG))
{
//if i2c hang on, ignore I2C data
i++;
if (i==9999)
//break;
WDTCTL =0;//reset
}
}
//while (!(UCB0IFG & UCTXIFG)); // check if UCB0TXBUF=empty

//Receive
UCB0CTL1 &= ~UCTR; // UCTR=0 => Receive Mode
IFG2 &= ~UCB0RXIFG;
IE2 &= ~UCB0TXIE; // disable Transmit ready interrupt
IE2 |= UCB0RXIE; // enable Receive ready interrupt
UCB0CTL1 |= UCTXSTT; // send start condition
i=0;
while(UCB0CTL1 & UCTXSTT) // Ensure start condition got sent
{
if(!(UCNACKIFG & UCB0STAT)) // Break out if ACK received
break;
}
for(loop=0;loop<number_of_read;loop++)
{
while (!(UCB0RXIFG & IFG2)); //recive data
UART_data[loop]=UCB0RXBUF;
}
UCB0CTL1 |= UCTXSTP; // send stop condition
while(UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
__no_operation();
UCB0CTL1 |= UCSWRST;
UCB0CTL1 &= ~UCSWRST;
_EINT();
}

5632:

#pragma vector = USCI_B1_VECTOR
__interrupt void USCI_B1_ISR(void)
{
switch(__even_in_range(UCB1IV,12))
{
case 0:// Vector 0: No interrupts
break;
case 2:// Vector 2: ALIFG
break;
case 4:// Vector 4: NACKIFG
break;
case 6:// Vector 6: STTIFG
UCB1IFG &= ~UCSTTIFG;
break;
case 8:// Vector 8: STPIFG
UCB1IFG &= ~UCSTPIFG;
if((I2C_Stat & 0x40)==0x40)
{
I2C_Stat=0;
UCB1IE &= ~UCTXIE;//Disable TX interrupt of I2C
}
break;
case 10:// Vector 10: RXIFG
I2C_data[(I2C_Stat&0x3F)] = UCB1RXBUF;// Get RXD byte into buffer
I2C_Stat++;
if((I2C_Stat&0x3F)>56)
{
I2C_Stat|=0x80;
}
break;
case 12:// Vector 12: TXIFG
UCB1TXBUF = I2C_data[I2C_TX_loop++];
break;
default:
break;
}
}

Sincerely,

Norton


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>