This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
I have working I2c code that was running on a previous design using a MSP430F5438A micro on UCB0. We switched to the MSP430F5659 and I needed to move to the UCB1 module on port 8 pins 5 and 6. I am running as the master and I get nothing on those port pins. There are external pull-ups on the board and both lines are always high. the I2C routines are polling, so no interrupts used.
I tried switching to the UCB0 module with the same code and it works fine...went back to UCB1 and still nothing. Any ideas as to why it wouldn't be working? Am i missing something odd about port 8?
Below are my I2C routines...
void InitializeI2C(void)
{
P8SEL |= BIT6; // enable SCL pin
P8SEL |= BIT5; // enable SDA pin
UCB1CTL1 |= UCSWRST; // hold serial controller in reset
UCB1CTL0 &= ~UCSLA10; // 7 bit slave address
UCB1CTL0 &= ~UCMM; // single master environment
UCB1CTL0 |= UCMST; // master mode
UCB1CTL0 |= UCMODE_3; // I2C mode
UCB1CTL0 |= UCSYNC; // synchronous mode
UCB1CTL1 |= UCSSEL_1; // select ACLK for clock source
UCB1BR0 = (I2C_CLOCK_PRESCALER & 0xFF); // LSB of clock prescaler
UCB1BR1 = (I2C_CLOCK_PRESCALER >> 8); // MSB of clock prescaler
UCB1CTL1 &= ~UCSWRST; // release serial controller out of reset
}
char I2CSendBytes(char address, char* txBuffer, char numBytes)
{
char bytesSent; // counts number of bytes sent
char errorCode; // holds error code to return
errorCode = 0; // preset error code to no error
UCB1CTL1 |= UCTR; // set to transmitter mode
UCB1IFG &= ~UCTXIFG; // Clear USCI_B1 TX int flag
UCB1I2CSA = address; // load address byte
timeout = 0; // initialize timeout counter
while ((UCB1CTL1 & UCTXSTP) && (!errorCode)) // wait for stop bit to have occured
{
if(timeout > I2C_SEND_TIMEOUT)
{
errorCode = I2C_RX_TIMEOUT_1;
}
}
UCB1CTL1 |= UCTXSTT; // transmit start condition
bytesSent = 0; // init counter
while(bytesSent < numBytes)
{
timeout = 0; // initialize timeout counter
while (((UCB1IFG & UCTXIFG) == 0) && (!errorCode)) // wait for transmit buffer to be ready
{
if(UCB1IFG & UCNACKIFG)
{
errorCode = I2C_NACK_RECEIVED;
}
if(timeout > I2C_SEND_TIMEOUT)
{
errorCode = I2C_TX_TIMEOUT_1;
}
}
UCB1IFG &= ~UCTXIFG; // Clear USCI_B0 TX int flag
UCB1TXBUF = txBuffer[bytesSent]; // load data byte
bytesSent++; // increment bytes sent counter
}
while (((UCB1IFG & UCTXIFG) == 0) && (!errorCode)) // wait for transmit buffer to be ready
{
if(timeout > I2C_SEND_TIMEOUT)
{
errorCode = I2C_TX_TIMEOUT_2;
}
}
UCB1IFG &= ~UCTXIFG; // Clear USCI_B0 TX int flag
if(errorCode)
{
UCB1CTL1 |= UCSWRST; // hold serial controller in reset
UCB1CTL1 &= ~UCSWRST; // release serial controller out of reset
}
else
{
UCB1CTL1 |= UCTXSTP; // transmit stop condition
}
return errorCode;
}
Hi, Thanks for your post!
I compared your code with the simple eUSCI_B0 I2C Master code example msp430f665x_uscib0_i2c_07 on MSP430F665x, MSP430F565x Code Examples (Rev. I). So far, I haven't found the abnormal code on your code. Please check following comments:
1, double check the external pull-up resistance is 10Kohm
2, change msp430f665x_uscib0_i2c_07 code example to uscib1 and test again because this code is simpler and used interrupt. P2 port mapping is not needed.
3, change your code to P9.6/UCB2SCL and P9.5/UCB2SDA instead of P8.6/UCB1SCL and P8.5/UCB1SDA and test if UCB2 works as the expecting.
Thanks!
Thanks for your response...I actually found a defect with the prototype board that was causing the problem...so everything is working now.
**Attention** This is a public forum