Other Parts Discussed in Thread: TLV320ADC3101
Tool/software: Code Composer Studio
Hi, All
Customer evaluate I2C communication between MSP 430F5242 and TLV320DAC32.
In order to check whether it is correctly written in Register, Register of same address is read after writing.
However, it seems that the register contents of the specified address + 1 are being read.
The figure below shows the waveform when 0x55 is written to Register Address 0x03 and then Register Address 0x03, 0x02 is read.
As a result, when Register Address 0x02 is read, 0x55 is output.
It seems that there is no problem comparing figure 24(I2C Write) and Figure 25(I2C Read) of Datasheet P22.
Do you know whether there is a problem with writing or reading?
Below is the MSP 430 Source Code.
reg = 0x03, num = 1
uchar I2C_read(uchar reg, uchar num, uchar *buf)
{
uchar tx_buf[10];
tx_buf[0]=reg;
PTxData = (uchar *)&tx_buf[0]; /* Tx Buffer Pointer Set */
UCB1CTL1 |= UCSWRST; /* Enable SW reset */
UCB1CTL0 = UCMST + UCMODE_3 + UCSYNC; /* I2C Master, synchronous mode */
UCB1CTL1 = UCSSEL_2 + UCSWRST; /* Use SMCLK, keep SW reset */
UCB1BR0 = 80; /* fSCL(8MHz) = SMCLK/80 = 100kHz(SMCLK/20 = 400kHz) */
UCB1BR1 = 0;
UCB1I2CSA = I2C_ADR; /* Slave Address */
UCB1CTL1 &= ~UCSWRST; /* Clear SW reset, resume operation */
UCB1IE |= UCTXIE; /* Enable TX interrupt */
UCB1IE |= UCRXIE; /* Enable RX interrupt */
TM1M_CNT = 200; /* time out */
FI2C_IRQ = OFF; /* Interrupt */
PRxData = (uchar *)buf; /* Rx Buffer Pointer Set */
RXByteCtr = 0;
TXByteCtr = 1;
while (UCB1CTL1 & UCTXSTP); // Ensure stop condition got sent
UCB1CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
while(1)
{
if (FI2C_IRQ == ON) break;
if (TM1M_CNT == 0) goto tm_err;
}
FI2C_IRQ = OFF; /* Interrupt */
//Receive process
RXByteCtr = 1;
while (UCB1CTL1 & UCTXSTP); // Ensure stop condition got sent
UCB1CTL1 &= ~UCTR ; // Clear UCTR
UCB1CTL1 |= UCTXSTT; // I2C start condition
while (UCB1CTL1 & UCTXSTT); // Start condition sent?
UCB1CTL1 |= UCTXSTP; // I2C stop condition
while(1)
{
if (FI2C_IRQ == ON) break;
if (TM1M_CNT == 0) goto tm_err;
}
return OK;
tm_err:
SetResponse((uchar *)"Tm err");
return ERROR; /* Error */
}
#pragma vector = USCI_B1_VECTOR
__interrupt void USCI_B1_ISR(void)
{
switch(__even_in_range(UCB1IV,12))
{
case 0: break; /* Vector 0: No interrupts */
case 2: break; /* Vector 2: ALIFG */
case 4: break; /* Vector 4: NACKIFG */
case 6: break; /* Vector 6: STTIFG */
case 8: break; /* Vector 8: STPIFG */
case 10: /* Vector 10: RXIFG */
case 12: /* Vector 12: TXIFG */
if(RXByteCtr == 1)
{ // Master Recieve?
*PRxData = UCB1RXBUF; // Get RX data
FI2C_IRQ = ON; /* Interrupt */
}
else
{ // Master Transmit
if (TXByteCtr) // Check TX byte counter
{
UCB1TXBUF = *PTxData; // Load TX buffer
TXByteCtr--; // Decrement TX byte counter
}
else
{
UCB1CTL1 |= UCTXSTP; // I2C stop condition
UCB1IFG &= ~UCTXIFG; // Clear USCI_B0 TX int flag
FI2C_IRQ = ON; /* Interrupt */
}
}
break;
default:break;
}
}
It is able to read and write normally using the same function as TLV320ADC3101 connected to the same I2C bus....
Please comment so that it can communicate normally with TLV320DAC32.
Best Regards,
Takashi