Hello,
I have been trying to use hardware I2C module on MSP430F169 chip,
unsuccessfully so far. Does anyone has any experience and/or pieces of code
for dealing with HW I2C ? The only sample code that I found was TI's slave
temperature sensor with DMA mode of I2C. Could not get it to work though:
when communicating from master, no ACK bits were sent.
Was unable to implement master transmitter mode as well. The problem was
that after setting I2CSTT (start condition bit), no I2CBB is generated, as
it follows from the MSP1x Family User's Guide master transmitter I2C state
diagram. I2CBB is not set in any reasonable time, further attempts to
initiate data transfer (writing to I2CDR , etc) don't seem to have any
result. I2C module never signals any of interrupt flags in I2CIFG.
Here is piece of code that was used (sorry, formatting may be lost):
//--------------------------------------------------------------------------
------
Initialization function (...)
// Setup I2C module
U0CTL = I2C + SYNC; // switch USART0 to I2C mode, slave
U0CTL &= ~I2CEN; // disable I2C module
I2CIE = STTIE | GCIE | TXRDYIE | RXRDYIE | ARDYIE | OAIE | NACKIE | ALIE;
I2CIFG = 0;
I2COA = DINC_I2CADDR_MCU;
I2CSA = DINC_I2CADDR_DSP;
I2CTCTL = I2CSSEL_2 + I2CWORD; // select SMCLK, word mode
I2CPSC = 0;
I2CSCLH = 3;
I2CSCLL = 3;
//--------------------------------------------------------------------------
------
Transmit function (...)
U0CTL &= ~I2CEN; // disable I2C module
U0CTL = SYNC + I2C + MST; // switch USART0 to I2C mode, master
I2CTCTL = I2CSSEL_2 + I2CWORD;
U0CTL |= I2CEN; // enable I2C module
I2CTCTL |= I2CTRX + I2CSTT; // generate start condition
tout = I2C_TIMEOUT_BUSY;
while(--tout) // wait for I2C busy flag
if(I2CDCTL & I2CBB) break;
if(tout == 0) {
error;
}
Kind Regards,
/Andrei