Other Parts Discussed in Thread: MSP430F5438A
Dear all, I'm using an MSP430F5438a, and dealing with several digital peripherals, there are some cases where I would like to avoid using ISR just to simply send or receive few bytes of configuration. Hence I'd kindly ask if the following code (meant for the USCI B2) might be correct or not.
Thanks in advance
Paolo
//===========================================================================
void I2C_WriteRegister (u8t SlaveAddr, u8t RegAddr, u8t Arg)
//===========================================================================
{
UCB2CTL1 |= UCTR + UCTXSTT; // I2C transmitter mode (TX), send START condition
while (UCB2IFG & !UCTXIFG); // Wait until start condition has been sent
UCB2IFG &= ~UCTXIFG; // Clear USCI TX int flag
UCB2TXBUF = SlaveAddr; // Load TX buffer with I2C Slave Address
while (!(UCB2IFG & UCTXIFG)); // Ensure the first byte got sent
if( !(UCB2IFG & UCNACKIFG) ) // Ensure the Slave answred an ACK
{
UCB2TXBUF = RegAddr; // Load TX buffer with I2C Slave Address
while (!(UCB2IFG & UCTXIFG)); // Ensure the first byte got sent
if( !(UCB2IFG & UCNACKIFG) ) // Ensure the Slave answred an ACK
{
UCB2TXBUF = Arg; // Load TX buffer with I2C Slave Address
while (!(UCB2IFG & UCTXIFG)); // Ensure the first byte got sent
}
}
UCB0CTL1 |= UCTXSTP; // I2C stop condition
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
}