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.

CCS/MSP430G2553: I2C code for FDC1004

Part Number: MSP430G2553
Other Parts Discussed in Thread: FDC1004EVM, ENERGIA

Tool/software: Code Composer Studio

Hi 

i was developing a board to measure the change in capacitance using MSP430G2553 and FDC. i bulit hardware and below code. 

i trying to read the device ID but i am reading only 1st byte of ID and not the second byte and also if i remove the LPM instructions code is not working please let me know what am i missing while developing this code.

#include <msp430g2553.h>


int TXByteCtr;
unsigned char PRxData[3];
int Rx = 0;
int i=0;
char REG_ID= 0xFE;

char itgAddress = 0x50;

void init_I2C(void);
void Transmit(void);
void Receive(void);


int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0
P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0
init_I2C();


while(1){
//Transmit process
Rx = 0;
TXByteCtr = 1;
Transmit();
//Receive process
Rx = 1;
Receive();
}
}

//-------------------------------------------------------------------------------
// The USCI_B0 data ISR is used to move received data from the I2C slave
// to the MSP430 memory. It is structured such that it can be used to receive
//-------------------------------------------------------------------------------
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void)
{
if(Rx == 1){ // Master Recieve?
for(i=0;i<3;i++)
{
PRxData[i] = UCB0RXBUF; // Get RX data
__bic_SR_register_on_exit(CPUOFF); // Exit LPM0
}
}

else{ // Master Transmit
if (TXByteCtr) // Check TX byte counter
{
UCB0TXBUF = REG_ID; // Load TX buffer
TXByteCtr--; // Decrement TX byte counter
}
else
{
UCB0CTL1 |= UCTXSTP; // I2C stop condition
IFG2 &= ~UCB0TXIFG; // Clear USCI_B0 TX int flag
__bic_SR_register_on_exit(CPUOFF); // Exit LPM0
}
}

}
void init_I2C(void) {
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = itgAddress; // Slave Address is 069h
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
IE2 |= UCB0RXIE + UCB0TXIE; //Enable RX and TX interrupt
}

void Transmit(void){
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
__bis_SR_register(CPUOFF+GIE); // Enter LPM0 w/ interrupts
}
void Receive(void)
{
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
UCB0CTL1 &= ~UCTR ; // Clear UCTR
UCB0CTL1 |= UCTXSTT; // I2C start condition
while (UCB0CTL1 & UCTXSTT); // Start condition sent?
UCB0CTL1 |= UCTXSTP; // I2C stop condition
__bis_SR_register(CPUOFF+GIE); // Enter LPM0 w/ interrupts
}

Regards

Nandish

 

  • Hi Nandish,

    Assuming that the transmission piece works and the hardware connection is solid since you are able to read the first byte, you need to work specifically on the code involving receiving multiple bytes. Please refer to the msp430g2xx3_uscib0_i2c_[10&12].c code examples for further information on how to set this up properly. You specifically seem to be stopping the I2C sequence immediately after requesting the first ID byte. You should also only have either RXIE or TXIE enabled at any time. Here is the FDC1004EVM Energia code for additional reference: www.ti.com/.../snvc187

    Regards,
    Ryan

**Attention** This is a public forum