Quantcast
Channel: Microcontrollers
Viewing all articles
Browse latest Browse all 229664

Forum Post: MSP430F6659 I2C Issue

$
0
0

Hello TI Forums,

I am developing I2C device drivers for the MSP430F6659 to transmit/receive data from a MEMS accelerometer. I developed the I2C drivers before for another device (MSP430F2418) and had no issue.  When doing an I2C read and releasing the UCB1 module from RST, I check the UCBBUSY flag just to ensure that the bus does not busy before issuing a start condition. However, I can never get pass this statement when stepping through with a debugger. Here is the sample code (initilization and i2c_read function):

void I2C_init()
{
UCB1CTL1 |= UCSWRST; // disable USCI

UCB1CTL0 = UCMST | UCMODE_3 | UCSYNC; // master mode, synchrnoucs, I2C mode

UCB1CTL1 = UCSSEL_2; // SMCLK Selected

UCB1I2CSA = 0x0f; //Slave Address

UCB1BR0 = 12; //I2C data rate ~100khz
UCB1BR1 = 0;

UCB1IE = UCSTPIE | UCSTTIE; // enable stop/start condition interrups

UCB1CTL1 &= ~UCSWRST; //enable USCI

}

char i2c_read(char device_address, char register_address)
{
char result;
UCB1I2CSA = device_address; // set slave address

__disable_interrupt();
UCB1CTL1 = UCSWRST; // reset the device
UCB1CTL1 &= ~UCSWRST; // release from reset

while(UCB1STAT & UCBBUSY); // stops here, never passes this line

UCB1CTL1 |= UCTXSTT + UCTR; //Start Condition sends address of slave, Transmit Mode

while( !(UCB1IFG & UCTXIFG) );//Wait until the data has been shifted out
UCB1TXBUF = register_address; //Load address of slave register

while (UCB1CTL1 & UCTXSTT); //Wait until the acknowlege message has been received //
while(UCB1STAT & UCBBUSY);

UCB1CTL1 &= ~UCTR; //Sets the master as a receiver
UCB1CTL1 |= UCTXSTT; //Start Condition sends address of slave

while(UCB1CTL1 & UCTXSTT);

UCB1CTL1 |= UCTXSTP; //Send stop message


while ( !(UCB1IFG & UCRXIFG) ); // wait till data recieves
result = UCB1RXBUF; //Save data to memory

while((UCB1CTL1 & UCTXSTP));

__enable_interrupt();

return result;

}

The errata for the MSP430F6659 does state that the UCBBUSY flag should be check before issuing a START condition. I have tried interfacing the board with a I2C analyzer to ensure that MEMS accelerometer is indeed working, and it did. Reading back the device ID of the accel was not an issue.

Any suggestions/questions concerning this is much appreciated.

-TIm  


Viewing all articles
Browse latest Browse all 229664

Latest Images

Trending Articles



Latest Images

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