I got this code from TI Forum. I tried to interface it with DS1307 RTC module from Maxim Electronics. I am able to send the slave address, but the code gets stuck when I am trying to send the register address.
Can somebody help me with this? I'm guessing that UCB0TXIFG is not getting set.
unsigned char read(unsigned char registerAddr) { unsigned char receivedByte = 0; UCB0I2CSA = 0xD0; // Slave Address is 069h while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent UCB0CTL1 |= UCTR + UCTXSTT; // I2C start condition with UCTR flag for transmit while((IFG2 & UCB0TXIFG) == 0); //UCB0TXIFG is set immidiately UCB0TXBUF = registerAddr; //write registerAddr in TX buffer while((IFG2 & UCB0TXIFG) == 0); //Code Gets stuck here. It does not proceed further UCB0CTL1 &= ~UCTR ; // Clear I2C TX flag for receive UCB0I2CSA = 0xD1; // Slave Address is 069h UCB0CTL1 |= UCTXSTT; // Repeated start while (UCB0CTL1 & UCTXSTT); // Start condition sent? RXBuffer full? UCB0CTL1 |= UCTXSTP; while((IFG2 & UCB0RXIFG) == 0); // wait until TX buffer is empty and transmitted //print("hello\r\n"); receivedByte = UCB0RXBUF; // I2C stop condition return receivedByte; }