Other Parts Discussed in Thread: MSP430F2618
Hi,
I am using USCB1 for I2c of msp430f2618 and slave is LIS331DLH accelerometer.
Below is the code::
I am writing 0x2f data to CNTRL_REG1(0x20) and reading back the same reg to confirm whether data has been written properly.
void main()
{
unsigned char rcv = 0;
WDTCTL = WDTPW + WDTHOLD;
// P2SEL |= 0x00;
P2DIR |= BIT7; //Accelerometer pins
P6DIR |= BIT0;
P2OUT |= BIT7; //CS |= 1; // make CS = HIGH for I2C mode
P6OUT |= BIT0; //SA0 |= 1;
if (CALBC1_16MHZ ==0xFF || CALDCO_16MHZ == 0xFF)
{
while(1); // If calibration constants erased
// do not load, trap CPU!!
}
BCSCTL1 = CALBC1_16MHZ; // Set DCO to 16MHz
DCOCTL = CALDCO_16MHZ;
P5SEL |= 0x06; // Assign I2C pins to USCI_B0
UCB1CTL1 |= UCSWRST; // Enable SW reset
UCB1CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
UCB1CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
UCB1BR0 = 42; // fSCL = SMCLK/40 = ~400kHz
UCB1BR1 = 0;
UCB1I2CIE |= UCNACKIE;
// UCB1I2CSA = 0x19;
UCB1CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
UC1IE |= UCB1TXIE+UCB1RXIE;
UCB1I2CSA = SlaveAddress;
while ((UCB1CTL1 & UCTXSTP));
UCB1CTL1 = UCTR + UCTXSTT;
UCB1TXBUF = 0x20;
while(!(UC1IFG & UCB1TXIFG)); // LINE 1
UCB1TXBUF = 0x2f;
while(!(UC1IFG & UCB1TXIFG));
UCB1CTL1 |= UCTXSTP; // I2C stop condition
UC1IFG &= ~UCB1TXIFG;
UCB1TXBUF = 0x20;
UCB1CTL1 &= ~UCTR;
UCB1CTL1 = UCTXSTT;
while(!(UC1IFG & UCB1TXIFG));
rcv = UCB1RXBUF;
UCB1CTL1 |= UCTXSTP;
UC1IFG &= ~UCB1TXIFG;
}
but the code is hanging at LINE 1 itself..