Hello,
I am extremely new at programming a microcontroller and would like you to help me out in the following program I have written.
I need to read and write using the I2C from MSP430F169 which has USART module to AD7150, a capacitance to digital converter.
The following program always gets stuck in the line highlighted below, during the first write session itself. I could have made a very silly mistake while programming, I am really sorry, but I really need help.
Also, while communication do I need to send the slave address myself along with the read/write bit? Or I don't have to, as I I have already mentioned the slave address in the register and R/W bit goes on its own during the start bit.
The pull up resistors are there at 100kOhm and the clock frequency when measured is 57.7kHz.
Any help or suggestion would be great!!
Thank you so much! I really appreciate it.
I2C_Init(); //I2C Initialisation
//CH1 setup Register
I2C_write(0x0B,0xCB);
//CH1 CAPDAC Register
I2C_write(0x11,0x8C);
//CH2 setup Register
I2C_write(0x0E,0xCB);
//CH2 CAPDAC Register
I2C_write(0x12,0x8C);
//I2C Initialisation
void I2C_Init(void)
{
P3SEL |= 0x0A; //Assign I2C pins to module
U0CTL |= SYNC + I2C +MST; // Synchronous, Switch USART0 to I2C mode, Set MSP430 as Master
U0CTL &= ~I2CEN;
I2CTCTL |= I2CSSEL_2 + I2CRM; // Set clock source as SMCLK, Repeat Mode
I2CSA = 0x48; //Slave Address
U0CTL |= I2CEN; // Enable I2C
}
//I2C Write Mode
void I2C_write(unsigned char address,unsigned char config)
{
I2CIE |= TXRDYIE; //Enable Transmit interrupt
I2CTCTL |= I2CTRX + I2CSTT + I2CSTP; //Initiate Transfer
while((I2CIFG & TXRDYIFG)==0); //Wait for transmitter to be ready
I2CDRB = address; //Send register address
while((I2CIFG & TXRDYIFG)==0); //Wait for transmitter to be ready
I2CDRB = config; // Send configuration data
while((I2CTCTL & I2CSTP)==0x02); // Wait for stop condition
I2CIE &= ~TXRDYIE; // Disable Transmit interrupt
}
//I2C Read Mode
void I2C_read(unsigned char address, unsigned char i)
{
I2CIE |= TXRDYIE; //Enable Transmit interrupt
I2CTCTL |= I2CTRX + I2CSTT + I2CSTP;
while((I2CIFG & TXRDYIFG)==0); //Initiate Transfer
I2CDRB = address; //Send register address from which data needs to be read
I2CIE &= ~TXRDYIE; // Disable Transmit interrupt
I2CIE |= RXRDYIE; //Enable Receive interrupt
I2CTCTL |= I2CSTT; // Restart condition
I2CTCTL &= ~I2CTRX; //MSP430 in Read mode
while((I2CIFG & RXRDYIFG)==0); //Wait for receiver to be ready
i = I2CDRB; // Receive MSByte from AD7150
i = i<<8;
while((I2CIFG & RXRDYIFG)==0); //Wait for receiver to be ready
i = i + I2CDRB; // Receive LSByte from AD7150
while((I2CTCTL & I2CSTP)==0x02); // Wait for stop condition
I2CIE &= ~RXRDYIE; // Disable receive interrupt
}