Hi,
I am using MSP430F1612 in my design and trying to communicate with external fuel gauge IC. Any body tried Repeated start by using software counter (I2CRM =
1)for Data tx/rx.
Clock: 8MHz (Configured as 4MHz for SMCLK)
I2Cinit as follows
/*Enable I2C module operation (not using them as GPIO) */ PORT3_GPIO_DIS(I2C_SCL_GPIO | I2C_SDA_GPIO); /* To set UART0 module to operate in I2C mode */ U0CTL |= I2C + SYNC; /* I2C operation is disabled */ U0CTL &= ~I2CEN; /* 7 bit addressing mode */ U0CTL &= ~XA; /* Master mode selection*/ U0CTL |= MST; /* Selection of SMCLK */ I2CTCTL |= I2CSSEL1; /* Prescaler Reg */ I2CPSC = 0x00; /* I2C Shift Clock High Reg*/ I2CSCLH = I2C_CLK_HIGH_REG_SEL; //0x12 /* I2C Shift Clock Low Reg*/ I2CSCLL = I2C_CLK_LOW_REG_SEL; //0x12 /* I2C Own 7 bit address */ I2COA =I2C_MASTER_ADDR; /* Select Byte Mode */ I2CTCTL &= ~I2CWORD; /* Number of bytes transmitted is controlled by the s/w
*/ I2CTCTL |= I2CRM; /* Enable I2C*/ U0CTL |= I2CEN; /* Idle condition - No Start*/ I2CTCTL &= ~I2CSTT ; /* Idle condition - No Stop */ I2CTCTL &= ~I2CSTP;
While writing and Reading these steps will be performed
/* Disable I2C*/ U0CTL &= ~I2CEN; /* Transmit mode */ I2CTCTL |= I2CTRX ; // I2CTCTL &= ~I2CTRX ; for receive mode /* Slave address 0 to 6 bits */ I2CSA = ucSlaveAddr>>1; /* Put the I2C in Byte mode*/ I2CDCTL |= I2CSBD; /* Enable I2C*/ U0CTL |= I2CEN; /* Master mode selection*/ U0CTL |= MST; /* Initiate Start */ I2CTCTL |= I2CSTT;
if ((I2CIFG & NACKIFG)) { return ERR_WRITE; }
then read or write the bits depends on Tx / Rx operation, if TXRDYIFG or RXRDYIFG is ready
and sent the stop bit (only for Read).
Timer interrupts are used for time out conditions. (No interrupts were used for I2C module)
This is code is working once in a while, but there is no consistency. few things i got from Errata but its not clear where i can use repeated start when I2CRM = 1.
In my code I2CWrite will be called in I2CRead so repeated start will occur (start again before sending stop). any suggestions or findings...
Observations in I2C Fail condition:
Controller is sending only the address of the device and ACK from device, and not able to transmit other data after that both the SCL and SDA are pulled high .