Hi,
I have implmenting I2C in MSP430f5335 with slave device AMC6821SDBQ temp sensor. In this i face the following issues
1. If i tried to read single byte only but my master read two bytes after that only it sends stop bit.For that i am written code using interrupt both rx and tx as follows
switch(i2cReg_ptr->UCBxIV)
{
case 2: // Vector 2: ALIFG
break;
case 4: // Vector 4: NACKIFG
// UCTXSTP - Generate Stop condition
i2cReg_ptr->UCBxCtl1 |= 0x04;
break;
case 6: // Vector 6: STTIFG
break;
case 8: // Vector 8: STPIFG
break;
case 10: // Vector 10: RXIFG
if(i2cRWBuf_ptr->size == 1) // size of the receive bytes
{
// UCTXSTP - Generate Stop condition
i2cReg_ptr->UCBxCtl1 |= 0x04;
*(i2cRWBuf_ptr->data) = i2cReg_ptr->UCBxRXBuf; // read data from rxbuf
i2cReg_ptr->UCBxIE &= ~(0x01); //disable Rx interrupt
}
break;
case 12: // Vector 12: TXIFG
if(i2cRWBuf_ptr->size > 0) //size of the data transmitted
{
// Transfer next byte
i2cReg_ptr->UCBxTXBuf = *(i2cRWBuf_ptr->data); // assign data to TXbuf
i2cRWBuf_ptr->size--;
i2cRWBuf_ptr->data++;
}
if(i2cRWBuf_ptr->size == 0)
{
// UCTXSTP - Generate Stop condition
i2cReg_ptr->UCBxCtl1 |= 0x04;
// Transfer completed
// Disable Transmit Interrupt
i2cReg_ptr->UCBxIE &= ~(0x02);
}
}
break;
If suppose i want to read device id i use the following sequence
i2ctransmit()
{
// Transmit Interrupt enable
i2cReg_ptr->UCBxIE |= 0x02;
// UCTR - Enable Transmit
i2cReg_ptr->UCBxCtl1 |= 0x10;
// UCTXSTT - Generate Start condition
i2cReg_ptr->UCBxCtl1 |= 0x02;
}
then it hit the interrupt i have the data to be transfer in *(i2cRWBuf_ptr->data) its assigned in interrupt.
i2creceive()
{
i2cReg_ptr->UCBxIE |= 0x01; // Receive Interrupt enable
i2cReg_ptr->UCBxCtl1 &= ~(0x10); // UCTR - Enable Receive
i2cReg_ptr->UCBxCtl1 |= 0x02; // UCTXSTT - Generate Start condition
}
can anyone guide me how to set stop bit for both transmit and receive of single byte in interrupt method.